How to Install MySQL Database Server on Ubuntu 26.04
02 Apr, 2026
Introduction
MySQL is a free, open-source relational database management system that stores and organizes data in structured tables with rows and columns. Many web applications, content management systems like WordPress, and e-commerce platforms use MySQL as their backend database. The database server supports ACID (Atomicity, Consistency, Isolation, Durability) compliance, transactions, and replication, making it suitable for both small projects and large-scale enterprise applications.
This guide teaches you how to install MySQL on Ubuntu 26.04.
Prerequisites
Before you start:
- Deploy an Ubuntu 26.04 server.
- SSH to your server using PuTTY for Windows or Open SSH for Linux and Mac OS.
- Create a non-root user with sudo privileges.
Install MySQL Server
The MySQL package is available by default on the Ubuntu repositories. To install the package, follow these steps.
-
Refresh your system's package list to ensure you get the latest available versions.
console$ sudo apt update -
Install the MySQL server package and the required dependencies.
console$ sudo apt install -y mysql-serverOutput:
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl libhtml-tagset-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmysqlclient24 libtimedate-perl liburi-perl mysql-client-9.0 mysql-client-core-9.0 mysql-common mysql-server-9.0 mysql-server-core-9.0 Suggested packages: libipc-sharedcache-perl mailx tinyca The following NEW packages will be installed: libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl libhtml-tagset-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmysqlclient24 libtimedate-perl liburi-perl mysql-client-9.0 mysql-client-core-9.0 mysql-common mysql-server mysql-server-9.0 mysql-server-core-9.0 0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded. Need to get 27.5 MB of archives. After this operation, 163 MB of additional disk space will be used. -
Verify the MySQL version.
console$ mysql --versionOutput:
mysql Ver 9.0.1-1ubuntu1 for Linux on x86_64 ((Ubuntu))
Run MySQL Secure Installation
MySQL includes a security script that helps you set a root password and remove insecure default settings. Run this script after the initial install to secure your database server.
-
Execute the MySQL secure installation script.
console$ sudo mysql_secure_installationOutput:
Securing the MySQL server deployment. Enter password for user root: -
Press Enter since no password is set yet.
Sorry, user 'root'@'localhost' is not allowed to change account information? -
Press Y to set a new root password.
Do you wish to continue with the password provided? : y New password: your_strong_password Re-enter new password: your_strong_password -
Press Y to remove anonymous users.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. -
Press Y to disable remote root login.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. -
Press Y to remove the test database.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. -
Press Y to reload privilege tables.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
Manage MySQL Service
MySQL runs as a system service on Ubuntu under the name mysql. You can manage this service using specific commands to start, stop, restart, and check the MySQL status. These commands ensure your MySQL installation runs smoothly and make maintenance easier on your system.
Check MySQL Service Status
$ sudo systemctl status mysql
Output:
● mysql.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
Active: active (running) since Wed 2026-03-11 08:45:22 UTC; 2min 10s ago
Process: 1245 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 1256 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 2271)
Memory: 365.2M (peak: 372.5M)
CPU: 2.345s
CGroup: /system.slice/mysql.service
└─1256 /usr/sbin/mysqld
Press Ctrl + C.
Start MySQL Service
$ sudo systemctl start mysql
Stop MySQL Service
$ sudo systemctl stop mysql
Restart MySQL Service
$ sudo systemctl restart mysql
Enable MySQL to Start on Boot
$ sudo systemctl enable mysql
Output:
Synchronizing state of mysql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable mysql
Configure MySQL to Accept Remote Connections (Optional)
By default, MySQL listens only on localhost. To allow remote clients to connect, you need to modify the MySQL configuration file and open the firewall port.
-
Open the main MySQL configuration file.
console$ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf -
Locate the
bind-addressdirective.INIbind-address = 127.0.0.1 -
Change
127.0.0.1to0.0.0.0to listen on all available network interfaces.INIbind-address = 0.0.0.0 -
Save and close the
/etc/mysql/mysql.conf.d/mysqld.cnffile by pressing Ctrl + X + Y. -
Restart MySQL to apply the configuration changes.
console$ sudo systemctl restart mysql
Create a Remote User
For security reasons, you should not use the root account for remote connections. Instead, create a dedicated user with specific privileges for remote access.
-
Log in to MySQL as the root user.
console$ sudo mysql -u root -pOutput:
Enter password: your_root_password Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 9.0.1-1ubuntu1 (Ubuntu) Copyright (c) 2000, 2024, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> -
Create a new remote user with a strong password.
MySQLmysql> CREATE USER 'remote_user'@'%' IDENTIFIED BY 'your_strong_password';Output:
Query OK, 0 rows affected (0.02 sec) -
Grant all privileges to the remote user.
MySQLmysql> GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;Output:
Query OK, 0 rows affected (0.01 sec) -
Apply the privilege changes.
MySQLmysql> FLUSH PRIVILEGES;Output:
Query OK, 0 rows affected (0.00 sec) -
Exit from the MySQL prompt.
MySQLmysql> EXIT;Output:
Bye
Configure Firewall for MySQL
If UFW (Uncomplicated Firewall) is active on your Ubuntu server, you need to allow traffic on port 3306, which is the default port MySQL uses.
-
Check the UFW status.
console$ sudo ufw statusOutput:
Status: active -
Allow MySQL port 3306.
console$ sudo ufw allow 3306/tcpOutput:
Rule added Rule added (v6) -
Verify the firewall rule.
console$ sudo ufw statusOutput:
Status: active To Action From -- ------ ---- 3306/tcp ALLOW Anywhere 3306/tcp (v6) ALLOW Anywhere (v6)
Test the MySQL Database Server
In this section, you'll test your MySQL installation by logging into the database server, creating a sample database and table, inserting some data, and querying the table to ensure everything functions correctly. This process helps verify that your installation works as expected and that you can seamlessly perform basic database operations.
-
Log in to MySQL with the root user.
console$ sudo mysql -u root -pOutput:
Enter password: your_root_password Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 9.0.1-1ubuntu1 (Ubuntu) mysql> -
Create a new
company_dbdatabase.MySQLmysql> CREATE DATABASE company_db;Output:
Query OK, 1 row affected (0.01 sec) -
List all databases and ensure your new database is available.
MySQLmysql> SHOW DATABASES;Output:
+--------------------+ | Database | +--------------------+ | company_db | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) -
Use the new
company_dbdatabase.MySQLmysql> USE company_db;Output:
Database changed -
Create a sample
employeestable.MySQLmysql> CREATE TABLE employees ( employee_id INT AUTO_INCREMENT PRIMARY KEY, full_name VARCHAR(100), email VARCHAR(255) );Output:
Query OK, 0 rows affected (0.03 sec) -
Populate the
employeestable with sample records.MySQLmysql> INSERT INTO employees(full_name, email) VALUES ('MARY ROE', 'mary_roe@example.com');Output:
Query OK, 1 row affected (0.01 sec)MySQLmysql> INSERT INTO employees(full_name, email) VALUES ('JAY SMITH', 'jay_smith@example.com');Output:
Query OK, 1 row affected (0.00 sec) -
Query the
employeestable to verify the records.MySQLmysql> SELECT employee_id, full_name, email FROM employees;Output:
+-------------+-----------+------------------------+ | employee_id | full_name | email | +-------------+-----------+------------------------+ | 1 | MARY ROE | mary_roe@example.com | | 2 | JAY SMITH | jay_smith@example.com | +-------------+-----------+------------------------+ 2 rows in set (0.00 sec) -
Exit from the MySQL prompt.
MySQLmysql> EXIT;Output:
Bye
Your MySQL database server is working as expected.
Conclusion
In this guide, you have installed MySQL on Ubuntu 26.04 using apt, secured the database server with the mysql_secure_installation script, configured remote access, created a dedicated remote user, opened the firewall port, and created a sample database with tables and records. Now that you have MySQL running, consider integrating the database with a web application using PHP with MySQLi or PDO, or connect it with Python using the mysql-connector-python library to build data-driven applications.