One place for hosting & domains

      How to Upgrade to Ubuntu 22.04 LTS


      Although Ubuntu 20.04 LTS (Long Term Support) is still supported, users should upgrade Ubuntu to the more recent 22.04 LTS. Upgrading to the new release ensures the system can access the most recent security upgrades and application packages. This guide describes how to perform an inline upgrade from Ubuntu 20.xx or 21.xx to 22.04.

      New Features in Ubuntu 22.04

      Ubuntu 22.04 LTS from Canonical is also referred to as “Jammy Jellyfish”. Ubuntu generally supports their LTS releases for five years, which means Ubuntu 22.04 is supported until April 2027. This is superior to the Ubuntu 20.04 schedule, where support ends in April 2025. In addition, most application developers test their programs more thoroughly against the latest LTS release.

      In addition to the longer support period, Ubuntu 22.04 includes these other features and improvements:

      • Enhanced performance and better power efficiency.
      • A better display, featuring double the frame rate.
      • New power management options.
      • Updated security patches.
      • GNOME 42, which includes a streamlined user interface, on-screen notifications, and better multi-monitor support.
      • Increased customization options.
      • Firefox availability through a Snap package.
      • New releases of applications and toolchains. Updates and enhancements are available for Apache, MySQL, Perl, PHP, PostgreSQL, Python, and Ruby.
      • A new version (5.15) of the Linux Kernel.

      Inline Upgrade versus Clean Install

      There are two ways to upgrade a node. These are the inline upgrade method and the clean install approach. This guide only explains how to perform an inline upgrade. However, it is important to understand both methods to make an informed choice.

      The Inline Upgrade Method

      In an inline upgrade, the primary node is upgraded in place using either the GUI or command line directives. Ubuntu downloads and installs the new release of the operating system on the same system. The files and applications on the system are left unchanged and the node can immediately resume operations after the upgrade. Some of the advantages and disadvantages of this method, and other factors to consider, are as follows:

      • This is the easiest and fastest method of upgrading a node. Depending on the size of the new release, the node might be fully operational in as little as 15 minutes.
      • The Ubuntu upgrade procedure is well tested and generally reliable.
      • Users do not have to remember to reinstall a critical program or import data from the original node.
      • It is impossible to avoid some downtime while the updates are installed and the system reboots and initializes. During this period, any websites or applications hosted on the node are inaccessible. It is crucial to declare a maintenance window or switch to a backup system for the duration of the upgrade.
      • There is a greater chance of complications. Some applications might not work properly after the upgrade and might have to be reinstalled. There is also a greater chance of data corruption.
      • This method of upgrading tends to retain “digital residue”. This includes unnecessary or outdated packages, patches, and data.
      • This method is recommended if the system is only one release behind and is mainly running a widely used and tested configuration such as a LAMP stack. An inline upgrade might run into more problems when the system configuration is complicated or includes in-house applications.

      Caution

      Although this process upgrades the Ubuntu operating system and most common programs, it does not necessarily upgrade every application. It is difficult to predict how the upgrade might affect these programs.

      The Clean Install Method

      The clean install method takes the opposite approach to the inline upgrade. This approach deploys a brand new Linode running the Ubuntu 22.04 release. All necessary applications are reinstalled and the backed-up data from the old node is copied over. After the new node is fully configured and operational, the old node is decommissioned.

      The pros and cons of a clean install are as follows:

      • It is easier to troubleshoot any problems because there are fewer dependencies.
      • The configuration tends to be cleaner. Old packages and unwanted files are not copied over.
      • This method takes a lot more effort and is more error prone. It is easy to forget to port over important applications and application data.
      • This method is a better choice if the system is running a much older release of Ubuntu or if the configuration is very convoluted. It is also a good choice for systems under the control of an Infrastructure as Code (IaC) application, like Terraform or Chef. These applications allow administrators to automatically provision a new remote node with a standard configuration.

      For an in-depth explanation of the clean install method, see the
      Linode guide to manually upgrading a node.

      Before You Begin

      1. If you have not already done so, create a Linode account and Compute Instance. See our
        Getting Started with Linode and
        Creating a Compute Instance guides.

      2. Follow our
        Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.

      3. Ensure there is at least 20 GB of disk space available. Verify the amount of disk space availability using the df -Th command.

      Note

      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you are not familiar with the sudo command, see the
      Users and Groups guide.

      How to Upgrade to Ubuntu 22.04 LTS

      This guide is designed for users who want to upgrade from Ubuntu 20.04 LTS to Ubuntu 22.04 LTS. However, it is generally applicable for upgrades to Ubuntu 22.04 from any release of Ubuntu 20.xx or 21.xx.

      If the Linode is running Ubuntu 18.xx or any earlier release, first upgrade it to Ubuntu 20.04 LTS. Then perform the steps in this guide to upgrade from Ubuntu 20.04 LTS to the 22.04 LTS. See the
      Linode guide to Upgrade to Ubuntu 20.04 for more information. Alternatively, if the Ubuntu software and applications are very old, it might make more sense to perform a clean install instead.

      Caution

      This operation cannot be canceled after it is started. Ensure there is a stable connection to the Linode and backup power is available.

      How to Prepare the Linode for the Upgrade

      To increase the chance of a successful upgrade, ensure the operating system and all applications are up to date. All data should be backed up and active user applications shut down.

      To prepare the Ubuntu system for the upgrade, follow these steps.

      1. Upgrade the Linode and ensure it is up to date.

        sudo apt update -y && sudo apt upgrade -y && sudo apt dist-upgrade -y
      2. To simplify the upgrade, remove unused packages and files.

        sudo apt autoremove -y && sudo apt autoclean -y
      3. Reboot the node to ensure any new kernel upgrades are installed. Linode makes new kernels available through the Linode cloud manager. Any updates are automatically applied to the node upon a reboot. For more information, see the
        Linode guide to monitoring and maintaining a system.

      4. Make a backup copy of the system configuration and all application data. The easiest way to do this is to back up the entire system. Subscribing to the
        Linode Backup Service allows you to take a manual snapshot before the upgrade.

      5. Stop as many non-critical user applications services as possible, including web and database servers. Focus on applications that might be subject to data corruption. To see a list of the active services, use the command systemctl | grep running.

        sudo systemctl | grep running
        ...
        apache2.service loaded active running The Apache HTTP Server
        ...
        mysql.service loaded active running MySQL Community Server
            
      6. Use the command sudo systemctl stop <application_name> to stop a service. The following example demonstrates how to stop the Apache web server instance.

        Caution

        Do not stop any essential system services such as ssh or any systemd entry.

        sudo systemctl stop apache2
      7. Allow connections on TCP port 1022 through the ufw firewall. This permits Ubuntu to use a fallback port if the main connection drops. After adding the rule, reload the firewall.

        sudo ufw allow 1022/tcp
        sudo ufw reload
        Firewall reloaded
            
      8. Confirm connections on TCP port 1022 are now allowed.

        Status: active
        
        To                         Action      From
        --                         ------      ----
        OpenSSH                    ALLOW       Anywhere
        Apache Full                ALLOW       Anywhere
        1022/tcp                   ALLOW       Anywhere
        OpenSSH (v6)               ALLOW       Anywhere (v6)
        Apache Full (v6)           ALLOW       Anywhere (v6)
        1022/tcp (v6)              ALLOW       Anywhere (v6)
            

      How to Install Ubuntu Release 22.04

      The node is now ready for the upgrade. Ensure the update manager is installed, then initiate the upgrade. The upgrade might take some time, depending on the configuration, and must not be interrupted. Ensure there is enough time to complete the entire upgrade before proceeding.

      Note

      The upgrade operation can be performed using either a LISH session or an SSH connection. A LISH session is safer, but if SSH is used, the upgrade manager opens a second port for redundancy. This guide uses SSH for the procedure to demonstrate the additional steps required.

      1. Ensure the update-manager-core package is installed. On many systems, this package might already be available.

        sudo apt install update-manager-core
      2. Confirm the release-upgrader is set to the correct release update mode. The file /etc/update-manager/release-upgrades must include the line Prompt=lts.

        sudo cat /etc/update-manager/release-upgrades
        File: /etc/update-manager/release-upgrades
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        
        # Default behavior for the release upgrader.
        
        [DEFAULT]
        # Default prompting and upgrade behavior, valid options:
        #
        #  never  - Never check for, or allow upgrading to, a new release.
        #  normal - Check to see if a new release is available.  If more than one new
        #           release is found, the release upgrader will attempt to upgrade to
        #           the supported release that immediately succeeds the
        #           currently-running release.
        #  lts    - Check to see if a new LTS release is available.  The upgrader
        #           will attempt to upgrade to the first LTS release available after
        #           the currently-running one.  Note that if this option is used and
        #           the currently-running release is not itself an LTS release the
        #           upgrader will assume prompt was meant to be normal.
        Prompt=lts
      3. Run the do-release-upgrade command to start the upgrade.

        Note

        To force an upgrade from the latest supported release to a development release, use the command do-release-upgrade -d. This guide focuses on upgrading to the latest supported release and does not use this flag.

      4. If the operation is performed using a SSH connection, Ubuntu verifies the SSH connection details and asks whether to continue. Answer y to continue.

        Continue running under SSH?
        
        This session appears to be running under ssh. It is not recommended
        to perform a upgrade over ssh currently because in case of failure it
        is harder to recover.
        
        If you continue, an additional ssh daemon will be started at port
        '1022'.
        Do you want to continue?
            
      5. Ubuntu asks the user to confirm the new SSH port is allowed through the firewall. The port should already be open. Press the Enter key to continue.

        Starting additional sshd
        
        To make recovery in case of failure easier, an additional sshd will
        be started on port '1022'. If anything goes wrong with the running
        ssh you can still connect to the additional one.
        If you run a firewall, you may need to temporarily open this port. As
        this is potentially dangerous it's not done automatically. You can
        open the port with e.g.:
        'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'
        
        To continue please press [ENTER]
            
      6. Ubuntu reads through the list of packages, builds the dependencies, and searches for internal package mirrors. If no mirrors are available, it prompts for approval to rewrite the sources.list file. Enter y to continue.

        Fetched 336 kB in 0s (0 B/s)
        Reading package lists... Done
        ...
        No valid mirror found
        
        While scanning your repository information no mirror entry for the
        upgrade was found. This can happen if you run an internal mirror or
        if the mirror information is out of date.
        
        Do you want to rewrite your 'sources.list' file anyway? If you choose
        'Yes' here it will update all 'focal' to 'jammy' entries.
        If you select 'No' the upgrade will cancel.
        
        Continue [yN]
            
      7. Ubuntu downloads the new packages and files. It determines which packages are no longer supported and requests approval to proceed. It also calculates how long the upgrade might take. To continue with the upgrade, answer y.

        Note

        To see details about the packages to be removed, installed, and upgraded, enter d. Enter q to exit the details screen. Then enter y to continue with the upgrade.

        Do you want to start the upgrade?
        
        
        14 installed packages are no longer supported by Canonical. You can
        still get support from the community.
        
        5 packages are going to be removed. 91 new packages are going to be
        installed. 571 packages are going to be upgraded.
        
        You have to download a total of 552 M. This download will take about
        2 minutes with you connection.
        
        Installing the upgrade can take several hours. Once the download has
        finished, the process cannot be canceled.
        
        Continue [yN]  Details [d]
            
      8. Ubuntu displays a pop-up asking whether to restart the services after the upgrade. Select either the <Yes> button to automatically restart them or <No> to restart them manually.

        Ubuntu Services Pop-up

      9. Ubuntu continues downloading the new packages. This can take a considerable length of time, especially if many applications have been installed. However, Ubuntu echoes the package names when it installs and processes them, allowing users to monitor the progress. During the upgrade, Ubuntu uses a pop-up to ask users how to handle the sshd_config file. Select the keep the local version currently installed option, and then choose <OK>.

        Ubuntu SSH Configuration Pop-up

      10. Ubuntu locates any obsolete packages and asks the user whether to remove them. Enter y to delete the outdated packages.

        Searching for obsolete software
        Reading state information... Done
        
        Remove obsolete packages?
        
        
        41 packages are going to be removed.
        
        Continue [yN]  Details [d]
            
      11. Ubuntu removes the packages and finalizes the upgrade. This stage might also take some length of time. Ubuntu informs the user that the upgrade is complete and prompts them to reboot the system. Select y to reboot and finalize the upgrade.

        System upgrade is complete.
        
        Restart required
        
        To finish the upgrade, a restart is required.
        If you select 'y' the system will be restarted.
        
        Continue [yN]
            

      How to Perform Post-Upgrade Clean-Up Activities

      Ubuntu has now been upgraded to version 22.04 LTS. After the Linode reboots, it is ready to resume operations. However, it is important to validate the upgrade. There are also still a few security concerns to fix and clean-up activities to perform. Log in to the Linode and perform the following steps.

      1. Use the lsb_release -a command to verify the correct release of Ubuntu is now installed. The Release attribute should be 22.04.

        No LSB modules are available.
        Distributor ID: Ubuntu
        Description:    Ubuntu 22.04.1 LTS
        Release:        22.04
        Codename:       jammy
            
      2. Optional: To validate the kernel version, use the uname command.

        Linux 5.15.0-53-generic x86_64
            
      3. To increase security, close port 1022 in the ufw firewall. Reload the firewall.

        sudo ufw delete allow 1022/tcp
        sudo ufw reload
      4. Confirm the firewall rules are updated.

        Status: active
        
        To                         Action      From
        --                         ------      ----
        OpenSSH                    ALLOW       Anywhere
        Apache Full                ALLOW       Anywhere
        OpenSSH (v6)               ALLOW       Anywhere (v6)
        Apache Full (v6)           ALLOW       Anywhere (v6)
            
      5. Ubuntu disables any third-party repositories during the upgrade. To search for disabled repositories, switch to the sources.list.d directory and list the entries.

        cd /etc/apt/sources.list.d
        ls -l
      6. Edit each list using a text editor. Remove the # symbol at the start of the affected entries, and save the file. In the following example, remove the # symbol in front of deb [arch=amd64].

        nano archive-application.list
        File: archive-application.list
        1
        2
        
        [DEFAULT]
        deb [arch=amd64] https://apt.releases.application-name.com jammy main
      7. Update any third-party repositories and remove unnecessary packages using apt commands.

        sudo apt update -y && sudo apt upgrade -y && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y

      Conclusion

      Users can access security updates and new features by upgrading to the new Ubuntu 22.04 LTS release. The two methods of updating a Linode are the inline update or the clean install. This guide explains how to perform an Ubuntu inline upgrade, which is the quickest and easiest method.

      To prepare to upgrade a Linode to Ubuntu 22.04 LTS, update and upgrade the node, back up the data, and stop all services. Use the do-release-upgrade command to initiate the upgrade and follow all Ubuntu prompts. After the upgrade, tighten up security, enable third-party archives, and perform some clean-up tasks. For more information about the Ubuntu 22.04 LTS release, see the
      Ubuntu server documentation.

      More Information

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.



      Source link

      How to Install Ghost CMS on Ubuntu 18.04 LTS


      Updated by Linode

      Written by Linode

      Ghost is an open source blogging platform that helps you easily create a professional-looking online blog. Ghost is a robust content management system (CMS) with a Markdown editor, an easy-to-use user interface, and beautiful themes. It is easy to install and update with Ghost-CLI.

      In This Guide

      In this guide, you’ll set up, deploy, and secure a Ghost v3.5.1 blog on a Linode running Ubuntu 18.04 LTS, using NGINX, MySQL, Node.js, NPM, Ghost-CLI, and Let’s Encrypt. For installation instructions for other distributions, click here.

      Note

      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, consult our Users and Groups guide.

      Replace each instance of example.com in this guide with your site’s domain name.

      Before you Begin

      1. This guide assumes that you’ve followed the steps in our Getting Started and Securing Your Server guides and have created a new user for Ghost with elevated sudo privileges. The example username used in this guide is ghostexample.

      2. Ensure that you have a valid domain name and properly configured DNS records for your domain.

      3. Ensure that your system is up to date:

        sudo apt update && sudo apt upgrade
        
      4. Install build-essential:

        sudo apt install build-essential
        

      Install Prerequisites

      Install NGINX

      NGINX will be used as a reverse proxy for your Ghost application:

      sudo apt install nginx
      

      Install MySQL

      1. Download and install MySQL:

        sudo apt install mysql-server
        
      2. Log into MySQL:

        sudo mysql
        
      3. Set a password for the root user with this command, replacing password with a strong password:

        ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
        
      4. Exit MySQL:

        quit
        

      Install Node.js and NPM

      Ghost is built on Node.js and follows Node’s Long Term Support (LTS) plan. Ghost only supports LTS versions of Node.js.

      Download and install Node.js:

      curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
      sudo apt install nodejs
      

      Install and Configure Ghost

      Install Ghost-CLI

      Ghost-CLI is a command line interface (CLI) tool that makes installing and updating Ghost easy. It sets up the database, configures NGINX as a reverse proxy, enables TLS/SSL security using Let’s Encrypt CA, automatically renews your SSL, and initializes Ghost as a systemd service.

      Install Ghost-CLI:

      sudo npm install -g [email protected]
      

      Install Ghost

      Install Ghost using the Ghost-CLI tool.

      1. Create the document root directory:

        sudo mkdir -p /var/www/ghost
        
      2. Change ownership of the /var/www/ghost directory to the non-root user with sudo privileges that you created. In this example, ghostexample is our username:

        sudo chown ghostexample:ghostexample /var/www/ghost
        sudo chmod 775 /var/www/ghost
        
      3. Navigate to the Ghost root directory:

        cd /var/www/ghost
        

        Note

        Installing Ghost in the /root or /home/{user} folder won’t work and results in a broken setup. Only use /var/www/{folder} because it has the correct permissions.

      4. Ensure that the directory is empty to avoid file conflicts:

        ls -a
        
      5. Install Ghost in production mode:

        ghost install
        
      6. Answer each question as prompted. For more information about each question, visit the Ghost documentation:

          
        ? Enter your blog URL: https://example.com
        ? Enter your MySQL hostname: localhost
        ? Enter your MySQL username: root
        ? Enter your MySQL password: thePasswordYouEnteredForRoot
        ? Enter your Ghost database name: exampleGhost
        Configuring Ghost
        Setting up instance
        
        Setting up "ghost" system user
        ? Do you wish to set up "ghost" mysql user? yes
        ? Do you wish to set up Nginx? yes
        ? Do you wish to set up SSL? yes
        ? Enter your email (used for Let's Encrypt notifications) [email protected]
        ? Do you wish to set up Systemd? yes
        ? Do you want to start Ghost? yes
        
        
      7. After installation is complete, run ghost ls to view running Ghost processes:

        ghost ls
        

      In the future when a newer version of Ghost is released, run ghost update from the /var/www/ghost directory to update to the newest version.

      Complete the Setup

      To complete the setup process, navigate to the Ghost configuration page by appending /ghost to the end of your blog’s URL or IP. This example uses https://example.com/ghost.

      1. On the welcome screen, click Create your account:

        Ghost Welcome Screen

      2. Enter your email, create a user, password, and blog title:

        Create Your Account Screen

      3. Invite additional members to your team. If you’d prefer to skip this step, click I’ll do this later, take me to my blog! at the bottom of the page.

        Invite Your Team Screen

      4. Navigate the Ghost admin area to create your first post, change your site’s theme, or configure additional settings:

        Ghost Admin Area

      Troubleshooting

      1. Troubleshoot the system for any potential issues when installing or updating Ghost:

        ghost doctor
        
      2. Get help about Ghost:

        ghost --help
        

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      This guide is published under a CC BY-ND 4.0 license.



      Source link

      How to Install MariaDB on Ubuntu 18.04 LTS


      Updated by Linode Contributed by Ryan Syracuse

      MariaDB is a fork of the popular cross-platform MySQL database management system and is considered a full drop-in replacement for MySQL. MariaDB was created by one of MySQL’s original developers in 2009 after MySQL was acquired by Oracle during the Sun Microsystems merger. Today MariaDB is maintained and developed by the MariaDB Foundation and community contributors with the intention of it remaining GNU GPL software.

      Note

      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, you can check our Users and Groups guide.

      Before You Begin

      1. Ensure that you have followed the Getting Started, the Securing Your Server guides, and the Linode’s hostname is set.

        To check your hostname run:

        hostname
        hostname -f
        

        The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN) if you have one assigned.

      2. Update your system:

        sudo apt update
        

      Install and Setup MariaDB

      Install MariaDB using the package manager.

      sudo apt install mariadb-server
      

      MariaDB will bind to localhost (127.0.0.1) by default. For information on connecting to a remote database using SSH, see our MySQL remote access guide, which also applies to MariaDB.

      Note

      Allowing unrestricted access to MariaDB on a public IP not advised but you may change the address it listens on by modifying the bind-address parameter in /etc/mysql/my.cnf. If you decide to bind MariaDB to your public IP, you should implement firewall rules that only allow connections from specific IP addresses.

      MariaDB Client

      The standard tool for interacting with MariaDB is the mariadb client, which installs with the mariadb-server package. The MariaDB client is used through a terminal.

      Root Login

      1. Log into MariaDB as the root user:

        sudo mysql -u root -p
        
      2. When prompted for login credentials, hit enter. By default MariaDB will authenticate you via the unix_socket plugin and credentials are not required.

        You’ll then be presented with a welcome header and the MariaDB prompt as shown below:

          
        MariaDB [(none)]>
        
        
      3. To generate a list of commands for the MariaDB prompt, enter h. You’ll then see:

          
        General information about MariaDB can be found at
        
        MariaDB Foundation
        List of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (?) Synonym for `help'. clear (c) Clear the current input statement. connect (r) Reconnect to the server. Optional arguments are db and host. delimiter (d) Set statement delimiter. edit (e) Edit command with $EDITOR. ego (G) Send command to mysql server, display result vertically. exit (q) Exit mysql. Same as quit. go (g) Send command to mysql server. help (h) Display this help. nopager (n) Disable pager, print to stdout. notee (t) Don't write into outfile. pager (P) Set PAGER [to_pager]. Print the query results via PAGER. print (p) Print current command. prompt (R) Change your mysql prompt. quit (q) Quit mysql. rehash (#) Rebuild completion hash. source (.) Execute an SQL script file. Takes a file name as an argument. status (s) Get status information from the server. system (!) Execute a system shell command. tee (T) Set outfile [to_outfile]. Append everything into given outfile. use (u) Use another database. Takes database name as argument. charset (C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (W) Show warnings after every statement. nowarning (w) Don't show warnings after every statement. For server side help, type 'help contents' MariaDB [(none)]>

      Securing the Installation

      1. After accessing MariaDB as the root user of your database, enable the mysql_native_password plugin to enable root password authentication:

        USE mysql;
        UPDATE user SET plugin='mysql_native_password' WHERE user='root';
        FLUSH PRIVILEGES;
        exit;
        
      2. Run the mysql_secure_installation script to address several security concerns in a default MariaDB installation:

        sudo mysql_secure_installation
        

      You will be given the choice to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options. You can read more about the script in the MariaDB Knowledge Base.

      Using MariaDB

      Create a New MariaDB User and Database

      1. Login to the database again. This time, if you set a password above, enter it at the prompt.

        sudo mysql -u root -p
        
      2. In the example below, testdb is the name of the database, testuser is the user, and password is the user’s password. You should replace password with a secure password:

        CREATE DATABASE testdb;
        CREATE user 'testuser'@localhost IDENTIFIED BY 'password';
        GRANT ALL ON testdb.* TO 'testuser' IDENTIFIED BY 'password';
        

        You can shorten this process by creating the user while assigning database permissions:

        CREATE DATABASE testdb;
        GRANT ALL ON testdb.* TO 'testuser' IDENTIFIED BY 'password';
        
      3. Then exit MariaDB:

        exit;
        

      Create a Sample Table

      1. Login as testuser, entering the password when prompted:

        sudo mysql -u testuser -p
        
      2. Create a sample table called customers:

        USE testdb;
        CREATE TABLE customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
        
        • This creates a table with a customer_id field of the type INT for integer.
          • This field is auto-incremented for new records and used as the primary key.
        • Two other fields are created, first_name and last_name for storing the customer’s name.
      3. View the new table:

        SHOW TABLES;
        
          
        +------------------+
        | Tables_in_testdb |
        +------------------+
        | customers        |
        +------------------+
        1 row in set (0.00 sec)
        
        
      4. Add some data:

        INSERT INTO customers (first_name, last_name) VALUES ('John', 'Doe');
        
      5. View the data:

        SELECT * FROM customers;
        
          
        +-------------+------------+-----------+
        | customer_id | first_name | last_name |
        +-------------+------------+-----------+
        |           1 | John       | Doe       |
        +-------------+------------+-----------+
        1 row in set (0.00 sec)
        
        
      6. Then exit MariaDB:

        exit;
        

      Reset the MariaDB Root Password

      If you forget your root MariaDB password, it can be reset.

      1. Stop the current MariaDB server instance.

        sudo systemctl stop mariadb
        
      2. Then execute the following command which will allow the database to start without loading the grant tables or networking.

        sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking"
        
      3. Restart MariaDB:

        sudo systemctl start mariadb
        
      4. Login to the MariaDB server with the root account, this time without supplying a password:

        sudo mysql -u root
        
      5. Use the following commands to reset root’s password. Replace password with a strong password:

        FLUSH PRIVILEGES;
        UPDATE mysql.user SET password = PASSWORD('password') WHERE user = 'root';
        
      6. Update the authentication methods for the root password:

        UPDATE mysql.user SET authentication_string = '' WHERE user = 'root';
        UPDATE mysql.user SET plugin = '' WHERE user = 'root';
        exit;
        
      7. Revert the environment settings to allow the database to start with grant tables and networking:

        sudo systemctl unset-environment MYSQLD_OPTS
        
      8. Then restart MariaDB:

        sudo systemctl restart mariadb
        
      9. You should now be able to log into the database with your new root password:

        sudo mysql -u root -p
        

      More Information

      You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

      This guide is published under a CC BY-ND 4.0 license.



      Source link