Install MySQL Server on Ubuntu, lock it down with the security script, and create your first database and user. Ubuntu 24.04 ships MySQL 8.0.
Full guide: Install MySQL on Ubuntu 24.04 and 22.04 (Secure Setup)
Related guide: Full MySQL / MariaDB setup guide
1. Install
sudo apt update
sudo apt install mysql-server
2. Secure it
Removes anonymous users and the test database and blocks remote root login.
sudo mysql_secure_installation
3. Create a database and user
Open the shell with sudo mysql, then create what your app needs.
CREATE DATABASE appdb;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'a-long-random-password';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
4. Verify
Log in as the new user and check the version.
mysql -u appuser -p -e 'SELECT VERSION(); SHOW DATABASES;'
5. Back it up
A simple nightly dump you can restore anywhere.
mysqldump --single-transaction appdb | gzip > appdb-$(date +%F).sql.gz
6. Troubleshooting
Service will not start: read its log. Disk full is a common cause.
sudo systemctl status mysql --no-pager
sudo journalctl -u mysql -n 50 --no-pager
df -h /var/lib/mysql
FAQ
MySQL or MariaDB?
Either works for most apps, including WordPress. Ubuntu's mysql-server package installs MySQL 8.0; MariaDB is available as mariadb-server.
Should port 3306 be open to the internet?
No. Keep it on localhost or allow only specific app servers, and use an SSH tunnel for admin.
Further reading: MySQL 8.0 reference manual