How to install and secure MySQL on Ubuntu
Updated 7/20/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 secure MongoDB with authentication
By default, MongoDB runs without a password. Here is how to enable authentication and create an admin user.
Updated 7/20/2026DatabasesHow to migrate a database between servers
Move a MySQL or PostgreSQL database to a new server with minimal downtime, using dump and restore.
Updated 7/20/2026DatabasesHow to connect an app to a remote database
Allow access to a database from another server, securely: bind address, dedicated user and firewall.
Updated 7/20/2026