CloudLinux.ro
Databases

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 pricing

Related tutorials