MySQL 9 brings improved performance, enhanced JSON support, and better replication capabilities over previous versions. Ubuntu 26.04 LTS includes MySQL 9 in its default repositories, making installation straightforward. This guide installs, secures, and verifies MySQL 9.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS server
- A user with sudo privileges
Step 1 – Install MySQL Server
sudo apt update
sudo apt install mysql-server -y
Step 2 – Check MySQL Version and Status
mysql --version
sudo systemctl status mysql
Step 3 – Run the Security Script
The mysql_secure_installation script removes test databases, anonymous users, and sets root password policy:
sudo mysql_secure_installation
Step 4 – Log In to MySQL
On Ubuntu, root uses auth_socket by default:
sudo mysql
Verify the version:
SELECT VERSION();
exit
Step 5 – Create a Database and User
sudo mysql
CREATE DATABASE appdb;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'SecurePassword2026!';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
exit
Step 6 – Test with the New User
mysql -u appuser -p
SHOW DATABASES;
exit
Step 7 – Enable Remote Access (optional)
To allow remote connections, edit the bind-address:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change bind-address to 0.0.0.0, then allow the port in UFW:
sudo ufw allow 3306/tcp
sudo systemctl restart mysql
Step 8 – Enable MySQL at Boot
sudo systemctl enable mysql
Conclusion
MySQL 9 is now installed and secured on Ubuntu 26.04 LTS. Your database server is ready to support PHP applications, Python services, and any other workloads that require a relational database.