How to Install MySQL on Ubuntu 26.04

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:
- Have access to an Ubuntu 26.04 server instance as a non-root user with sudo privileges.
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.
Refresh the APT package index.
console$ sudo apt update
Install the MySQL server package.
console$ sudo apt install mysql-server -y
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.
Enable MySQL to start automatically at boot time.
console$ sudo systemctl enable mysql
Start the MySQL server.
console$ sudo systemctl start mysql
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.
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.
Open the MySQL server configuration file using a text editor such as Nano.
console$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Add the following directive under the
[mysqld]section to activate themysql_native_passwordauthentication plugin.inimysql_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.
Restart MySQL to load the updated configuration.
console$ sudo systemctl restart mysql
Access the MySQL console as the
rootsystem user.console$ sudo mysql
Assign a strong password to the root account. Replace
your_strong_passwordwith a secure password that meets your validation policy.sqlmysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password';
Reload the privilege tables to apply the password change.
sqlmysql> FLUSH PRIVILEGES;
Exit the MySQL console.
sqlmysql> 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.
Log in to the MySQL server as the
rootuser.console$ mysql -u root -p
The system prompts for a password. Enter the root password you set in the previous section.
Create a new database named
example_db.sqlmysql> CREATE DATABASE example_db;
Create a database user named
example_userwith a strong password. Replacedbuser_passwordwith your desired password.sqlmysql> CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'dbuser_password';
Grant the user full privileges on the
example_dbdatabase.sqlmysql> GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
Grant the user permission to create new databases.
sqlmysql> GRANT CREATE ON *.* TO 'example_user'@'localhost';
Grant the user permissions to perform read and write operations across all databases.
sqlmysql> GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'example_user'@'localhost';
Reload the privilege tables to activate the new user permissions.
sqlmysql> FLUSH PRIVILEGES;
Exit the MySQL console.
sqlmysql> 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.
Log in to the MySQL server as
example_user.console$ mysql -u example_user -p
Enter the
example_userpassword when prompted.List all databases accessible to the current user.
sqlmysql> SHOW DATABASES;
Your output should be similar to the one below:
+--------------------+ | Database | +--------------------+ | example_db | | information_schema | | mysql | | performance_schema | | sys | +--------------------+Create a new database named
example_demo.sqlmysql> CREATE DATABASE example_demo;
Switch to the new database.
sqlmysql> USE example_demo;
Create a table named
serviceswith columns for an auto-incrementing ID, a name, a description, and a timestamp.sqlmysql> CREATE TABLE services ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, description TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Insert sample records into the
servicestable.sqlmysql> 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.');
Query the table to verify that the data was inserted correctly.
sqlmysql> 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)Exit the MySQL console.
sqlmysql> 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.