How to Install MySQL on Ubuntu 26.04

Updated on 24 April, 2026
Install and configure the MySQL relational database management system on an Ubuntu 26.04 with security hardening and database administration.
How to Install MySQL on Ubuntu 26.04 header image

MySQL is an open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL) to organize, query, and manage data. It powers a wide range of applications, from content management systems and e-commerce platforms to analytics dashboards. MySQL supports features such as transactions, replication, and indexing, making it suitable for both development and production workloads.

This article explains how to install MySQL on an Ubuntu 26.04 server. It covers the database server setup, service management, security hardening through the built-in secure installation script, and basic database operations including user creation and table management.

Prerequisites

Before you begin, you need to:

Install MySQL on Ubuntu 26.04

The default Ubuntu 26.04 APT repositories include the MySQL server package. The following steps refresh the package index and install the latest available MySQL version from the official repositories.

  1. Refresh the APT package index.

    console
    $ sudo apt update
    
  2. Install the MySQL server package.

    console
    $ sudo apt install mysql-server -y
    
  3. Confirm the installed MySQL version.

    console
    $ mysql --version
    

    Your output should be similar to the one below:

    mysql  Ver 8.4.8-0ubuntu1 for Linux on x86_64 ((Ubuntu))

Manage the MySQL System Service

The mysql systemd service controls the MySQL database server process. Enable the service to persist across reboots and verify that the server is running.

  1. Enable MySQL to start automatically at boot time.

    console
    $ sudo systemctl enable mysql
    
  2. Start the MySQL server.

    console
    $ sudo systemctl start mysql
    
  3. Verify that the MySQL service is active and running.

    console
    $ sudo systemctl status mysql
    

    Your output should be similar to the one below:

    ● mysql.service - MySQL Community Server
         Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
         Active: active (running) since Wed 2026-03-25 13:42:49 UTC; 2min 41s ago
     Invocation: 9bea1ea520bb4872bfa0cc93d60f4f72
       Main PID: 22654 (mysqld)
         Status: "Server is operational"
          Tasks: 34 (limit: 6206)
         Memory: 478.7M (peak: 479.1M)

Secure the MySQL Server

A fresh MySQL installation allows the root user unrestricted console access without a password. The mysql_secure_installation script removes insecure defaults, and a separate configuration change enables the mysql_native_password authentication plugin so you can assign a password to the root account.

  1. Run the MySQL secure installation script.

    console
    $ sudo mysql_secure_installation
    

    Respond to each prompt as described below to harden the server:

    • VALIDATE PASSWORD COMPONENT: Enter Y and press Enter to activate password validation.
    • Password Validation Policy: Enter 2 to require strong passwords.
    • Remove anonymous users?: Enter Y to delete anonymous database accounts.
    • Disallow root login remotely?: Enter Y to restrict root access to the local server.
    • Remove test database and access to it?: Enter Y to drop the default test database.
    • Reload privilege tables now?: Enter Y to refresh the privilege tables and apply all changes.
  2. Open the MySQL server configuration file using a text editor such as Nano.

    console
    $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    
  3. Add the following directive under the [mysqld] section to activate the mysql_native_password authentication plugin.

    ini
    mysql_native_password=ON
    

    The [mysqld] section should look similar to the one below:

    ini
    ...
    [mysqld]
    #
    # * Basic Settings
    #
    mysql_native_password=ON
    user            = mysql
    ...
    

    Save and close the file.

  4. Restart MySQL to load the updated configuration.

    console
    $ sudo systemctl restart mysql
    
  5. Access the MySQL console as the root system user.

    console
    $ sudo mysql
    
  6. Assign a strong password to the root account. Replace your_strong_password with a secure password that meets your validation policy.

    sql
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password';
    
  7. Reload the privilege tables to apply the password change.

    sql
    mysql> FLUSH PRIVILEGES;
    
  8. Exit the MySQL console.

    sql
    mysql> EXIT;
    

Access MySQL

The MySQL command-line client provides an interface for database administration and query execution. The following steps log in as the root user, create a database, and configure a dedicated user with the necessary privileges.

  1. Log in to the MySQL server as the root user.

    console
    $ mysql -u root -p
    

    The system prompts for a password. Enter the root password you set in the previous section.

  2. Create a new database named example_db.

    sql
    mysql> CREATE DATABASE example_db;
    
  3. Create a database user named example_user with a strong password. Replace dbuser_password with your desired password.

    sql
    mysql> CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'dbuser_password';
    
  4. Grant the user full privileges on the example_db database.

    sql
    mysql> GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
    
  5. Grant the user permission to create new databases.

    sql
    mysql> GRANT CREATE ON *.* TO 'example_user'@'localhost';
    
  6. Grant the user permissions to perform read and write operations across all databases.

    sql
    mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'example_user'@'localhost';
    
  7. Reload the privilege tables to activate the new user permissions.

    sql
    mysql> FLUSH PRIVILEGES;
    
  8. Exit the MySQL console.

    sql
    mysql> EXIT;
    

Create a Sample MySQL Database

The example_user account has the privileges required to create and manage databases independently. The following steps log in as that user, create a new database with a sample table, and populate it with test data.

  1. Log in to the MySQL server as example_user.

    console
    $ mysql -u example_user -p
    

    Enter the example_user password when prompted.

  2. List all databases accessible to the current user.

    sql
    mysql> SHOW DATABASES;
    

    Your output should be similar to the one below:

    +--------------------+
    | Database           |
    +--------------------+
    | example_db         |
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
  3. Create a new database named example_demo.

    sql
    mysql> CREATE DATABASE example_demo;
    
  4. Switch to the new database.

    sql
    mysql> USE example_demo;
    
  5. Create a table named services with columns for an auto-incrementing ID, a name, a description, and a timestamp.

    sql
    mysql> CREATE TABLE services (
             id INT AUTO_INCREMENT PRIMARY KEY,
             name VARCHAR(255) NOT NULL,
             description TEXT,
             created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
             );
    
  6. Insert sample records into the services table.

    sql
    mysql> INSERT INTO services (name, description) VALUES
           ('Cloud Compute', 'Scalable virtual machines for general workloads.'),
           ('Object Storage', 'S3-compatible storage for unstructured data.'),
           ('Load Balancer', 'Distributes traffic across multiple server instances.');
    
  7. Query the table to verify that the data was inserted correctly.

    sql
    mysql> SELECT * FROM services;
    

    Your output should be similar to the one below:

    +----+----------------+-------------------------------------------------------+---------------------+
    | id | name           | description                                           | created_at          |
    +----+----------------+-------------------------------------------------------+---------------------+
    |  1 | Cloud Compute  | Scalable virtual machines for general workloads.      | 2026-03-25 17:55:40 |
    |  2 | Object Storage | S3-compatible storage for unstructured data.          | 2026-03-25 17:55:40 |
    |  3 | Load Balancer  | Distributes traffic across multiple server instances. | 2026-03-25 17:55:40 |
    +----+----------------+-------------------------------------------------------+---------------------+
    3 rows in set (0.00 sec)
  8. Exit the MySQL console.

    sql
    mysql> EXIT;
    

Conclusion

You have installed and secured MySQL on an Ubuntu 26.04 server, created a dedicated database user, and performed basic table operations. MySQL integrates with application stacks such as LAMP and LEMP, and supports replication for high-availability deployments. For more information, refer to the official MySQL documentation.

Comments