Securing a MySQL installation goes beyond user privileges. A hardened MySQL server limits the attack surface and protects against both external attacks and internal misuse.
Essential Hardening Steps
- Run mysql_secure_installation after every fresh install to set the root password, remove anonymous users, and disable remote root login.
- Disable remote root access — the root user should only connect from localhost.
- Remove the test database — it is accessible to all users by default.
- Bind to localhost — set bind-address = 127.0.0.1 in my.cnf if no remote connections are needed.
- Enable the audit log plugin — records all queries for compliance and forensics.
- Keep MySQL updated — security patches are released regularly.
- Use a firewall — only allow port 3306 from trusted IP addresses.
Checking for Anonymous Users
Query the mysql.user table to find and remove anonymous accounts and accounts with empty passwords.