MySQL 8.0 is the world’s most popular open-source relational database. Ubuntu 24.04 LTS ships with MySQL 8.0 in its default repositories. This guide installs, secures, and verifies MySQL on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A user with sudo privileges
Step 1 – Update Package Lists
Refresh the package index:
sudo apt update
Step 2 – Install MySQL Server
Install from the Ubuntu repository:
sudo apt install mysql-server -y
Step 3 – Start and Enable MySQL
Start and enable on boot:
sudo systemctl start mysql
sudo systemctl enable mysql
Step 4 – Run the Security Script
Secure the installation with the built-in wizard:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove the test database.
Step 5 – Log In to MySQL
Connect to the MySQL shell as root:
sudo mysql
Or with a password:
mysql -u root -p
Step 6 – Create a Database and User
Inside the MySQL shell:
CREATE DATABASE mydb;
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON mydb.* TO 'dbuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 7 – Verify the Installation
Check the MySQL version:
mysql --version
Check service status:
sudo systemctl status mysql
Step 8 – Allow Remote Connections (optional)
Edit the MySQL config to listen on all interfaces:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Change bind-address to 0.0.0.0, then restart MySQL and open UFW:
sudo systemctl restart mysql
sudo ufw allow 3306/tcp
Conclusion
MySQL 8.0 is now installed and secured on Ubuntu 24.04 LTS. Create dedicated database users for each application and never use the root account for application connections.