How to install and secure MySQL on Ubuntu
Updated 11/29/2026
MySQL is the most widely used open-source database. Here is how to install it and, just as important, how to secure it on an Ubuntu VPS.
1. Install
apt-get update -y
apt-get install -y mysql-server
systemctl enable --now mysql
2. Secure it
Run the official hardening script, which sets the root password and removes anonymous users and the test database:
mysql_secure_installation
3. Check access
mysql -u root -p
4. Best practices
- Do not use the root account for applications; create a dedicated user per app (see MySQL users and privileges).
- Keep MySQL local-only (
bind-address = 127.0.0.1) unless you need remote access. - Keep a regular backup on a Backup Box.
Or install it with one click
If you want to skip the setup, pick MySQL from the one-click app catalog when creating the server, with an auto-generated password.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to install and secure PostgreSQL on Ubuntu
Install the most advanced open-source database and configure it safely: password, scram-sha-256 authentication and controlled access.
Updated 11/29/2026DatabasesHow to create users and databases in PostgreSQL
Create roles, databases and grant privileges in PostgreSQL, step by step.
Updated 11/29/2026DatabasesHow to create a MySQL user and grant privileges
Create dedicated MySQL users per application and grant exactly the privileges needed, step by step.
Updated 11/29/2026