Home / Guides

Server guide

MySQL Security Hardening Checklist

This guide is for small businesses, agencies and hosting teams that run MySQL on Linux or Windows. It shows you what to check, how to fix common weaknesses, and how to keep your database safe over time.

8 min readUpdated November 2026 by the RootManage teamWorks on Ubuntu, Debian, AlmaLinux and Rocky unless noted

The short answer

Use this checklist to identify weak points in MySQL, apply secure settings, and maintain a hardened environment. Follow the steps to reduce exposure and protect your data.

Why MySQL Hardening Matters

An insecure MySQL installation is a primary target for attackers because it often holds sensitive customer data, credentials, and business records. If your database is exposed to the public internet, automated bots can scan for weak passwords or default configurations within seconds. Once compromised, attackers can read, modify, or delete data, leading to significant operational disruption and potential regulatory issues. Hardening reduces this attack surface by ensuring that only authorized applications and users can connect to your database services.

Default settings are often too permissive for production environments. Many installations come with anonymous users, test databases, or root access enabled without strong password protection. These configurations create easy entry points for malicious actors. By tightening permissions, removing unused features, and restricting network access, you significantly lower the risk of unauthorized access. This proactive approach protects your data integrity and ensures that your database remains a secure foundation for your web applications and business operations.

  • Remove anonymous user accounts and test databases.
  • Ensure root access requires a strong password.
  • Restrict database connections to specific application servers.
  • Disable remote root login from the internet.

How to Check Current MySQL Security

Begin by reviewing the MySQL configuration file, usually located at /etc/my.cnf or /etc/mysql/my.cnf. Look for the bind-address directive; if it is set to 0.0.0.0, the server accepts connections from any network, which may be unnecessary for a single‑host deployment. Also check for the skip-networking option, which disables TCP/IP networking entirely and forces local socket connections only. Verify that the sql_mode includes restrictive settings such as NO_AUTO_CREATE_USER and STRICT_TRANS_TABLES to reduce accidental privilege escalation.

Next, enumerate existing accounts and their host specifications with the query SELECT User, Host, plugin, authentication_string FROM mysql.user;. Identify any anonymous users, accounts with empty passwords, or users allowed from % (any host). Review the privileges granted to each account using SHOW GRANTS FOR 'user'@'host';. Ensure that only required accounts exist, each limited to the minimum privileges needed for their role, and that remote access is granted only where explicitly required.

  • Check bind-address and skip-networking in the MySQL config file.
  • List all MySQL users and their host patterns.
  • Identify accounts with empty passwords or using the mysql_native_password plugin.
  • Review granted privileges for each account.
  • Confirm that remote connections are allowed only for specific IPs.
terminal
mysql -N -e "SELECT User, Host FROM mysql.user;"

The output should show only the accounts you expect, each tied to a specific host or IP. Any user with Host set to % or an empty password indicates a potential exposure and should be tightened or removed.

Steps to Harden MySQL

MySQL can be hardened by limiting user privileges and enforcing strong authentication. Begin by disabling remote root login. In the MySQL configuration file, set bind-address to 127.0.0.1 and comment out any skip-networking lines that enable external access. Then use the MySQL client to revoke any GRANT statements that allow root or other users to connect from hosts other than localhost. Create application accounts with only the privileges they need, and avoid using the root account for application code. This reduces the attack surface and ensures that a compromised account cannot affect the entire database server.

Next, enable encryption for data at rest and in transit. For in‑transit encryption, add ssl=ON and specify the paths to the CA, certificate, and key files in the [mysqld] section. For data at rest, use MySQL’s built‑in tablespace encryption by setting innodb_encrypt_tables=ON and innodb_encrypt_log=ON. Finally, enable the MySQL audit plugin to log all login attempts and SQL statements. Regularly review these logs for suspicious activity and keep the server patched with the latest security updates.

What to Avoid in MySQL Security

Many administrators leave the root user accessible from remote hosts, which is a critical vulnerability. You should restrict root login to the localhost interface only. Additionally, avoid creating users with the 'ALL PRIVILEGES' grant unless absolutely necessary. Instead, apply the principle of least privilege by assigning specific permissions like SELECT or INSERT to application accounts. This limits the damage if a database credential is compromised or an application is exploited.

Another common mistake is leaving default or anonymous users in the MySQL installation. These accounts often have empty passwords and can be exploited by attackers to gain unauthorized access. You must remove these entries from the user table. Also, avoid storing sensitive data in plain text within the database. Use encryption at the application layer before saving data. Regularly review your user list to ensure no unnecessary accounts remain active on the system.

  • Remove anonymous user entries from the MySQL user table.
  • Restrict root user access to localhost only.
  • Avoid granting ALL PRIVILEGES to application-specific accounts.
  • Disable remote root access in the configuration file.
terminal
mysql -u root -p -e "SELECT User, Host FROM mysql.user;"

Review the output to identify any users with empty hosts or unexpected access rights. Verify that the root user is limited to the localhost host. If you see anonymous users, plan to remove them carefully after taking a backup of your database.

Keeping MySQL Secure Over Time

Regularly update your MySQL server to the latest stable version to patch known vulnerabilities. Check your package manager for available security updates and apply them during a scheduled maintenance window. Always review release notes to understand any breaking changes before upgrading production databases. Keeping your software current is one of the most effective ways to maintain a strong security posture against emerging threats.

Implement automated, encrypted backups of your databases at least daily. Store these backups in a separate, secure location, such as an off-site cloud storage bucket or a dedicated backup server. Test your restore procedures regularly to ensure that backups are actually usable in an emergency. Document your retention policy and verify that you have enough historical copies to recover from accidental deletions or ransomware incidents.

  • Enable binary logging to support point-in-time recovery options.
  • Monitor database logs for unexpected access patterns or errors.
  • Review user privileges quarterly to remove unnecessary access rights.
  • Keep configuration files version-controlled to track changes over time.
terminal
systemctl status mysqld
mysqladmin status
mysqldump --all-databases > /backup/full_backup.sql

Check the output for any active connections that you do not recognize. Verify that the backup file size matches expectations and confirm that the timestamp reflects the most recent successful run. If the service status shows any failures, investigate the logs immediately to resolve underlying issues.

Common MySQL Hardening Mistakes

A common mistake is leaving the default 'root' account with a blank password or a weak one. Attackers often scan for MySQL instances that allow password‑less logins and gain full control instantly. Even if you later set a strong password, any script or application that still uses the old credentials can re‑expose the server. Always verify that the root account requires a password and that no anonymous users exist, because these leftovers nullify other hardening steps such as network firewalls and encryption.

Another frequent error is granting overly broad privileges to service accounts. Administrators sometimes assign 'ALL PRIVILEGES' on every database to a single user for convenience. This practice defeats the principle of least privilege and gives an attacker who compromises that account unrestricted access. Similarly, using the same MySQL user for multiple applications without restricting host access can allow lateral movement. Regularly audit user grants and limit each account to only the databases and operations it truly needs.

  • Leaving the 'root' account with no password or a weak password.
  • Retaining anonymous users that were created during installation.
  • Granting 'ALL PRIVILEGES' to application users on all databases.
  • Allowing remote connections from any host (e.g., using '%' as host).
terminal
mysql -u root -p -e "SELECT User, Host, authentication_string FROM mysql.user;"

Review the output to ensure only required users exist, each has a strong password hash, and the Host column limits connections to trusted IPs or localhost.

Tools and Resources for MySQL Security

MySQL security can be strengthened by using a set of well‑tested tools that audit configuration, detect weak passwords, and monitor for suspicious activity. The most common utilities are the built‑in mysql_secure_installation script, which guides you through disabling remote root access and removing test databases; mysqldump for regular backups; and mysqlcheck for table integrity checks. For more advanced analysis, the open‑source sqlmap can test for injection vulnerabilities, while MySQL Workbench offers a graphical interface for reviewing user privileges and SSL settings. These tools are widely documented in the official MySQL manuals and community forums, and they are safe to run on production systems when used with caution. In addition to command‑line utilities, a number of external resources provide best‑practice guidance. The MySQL Enterprise Security Guide, available for download, offers detailed recommendations on hardening. The CIS Benchmarks provide a checklist for secure MySQL installations, and the OpenSCAP project offers an automated scanner that can validate compliance with those benchmarks. Finally, the mysqltuner.pl script offers quick, actionable suggestions based on current server metrics, helping you fine‑tune buffer sizes and connection limits for both performance and security.

MySQL security is an ongoing process. After applying hardening measures, always review the MySQL error logs for unexpected authentication failures, monitor the SHOW PROCESSLIST output for long‑running queries, and confirm that the user table contains only the accounts you need. Keep your server’s operating system and MySQL version up to date, and test any changes in a staging environment before applying them to production.

If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.

Questions people ask

What is the default MySQL root password policy?

The default MySQL installation uses a simple password policy that only checks length; it does not enforce complexity, expiration, or reuse rules unless the validate_password plugin is enabled. By default, root can set any password, so you should configure a stronger policy manually.

How do I restrict MySQL to local connections only?

To limit MySQL to local connections, edit the MySQL server’s bind-address in the configuration file (usually `/etc/my.cnf` or `/etc/mysql/mysql.conf.d/mysqld.cnf`) and set it to `127.0.0.1`. Then restart the MySQL service so it only listens on the loopback interface.

Which MySQL user privileges should I remove for a web app?

For a web‑application account, keep only the privileges it truly needs: typically `SELECT`, `INSERT`, `UPDATE`, `DELETE`, and maybe `EXECUTE` for stored procedures. Remove administrative rights such as `CREATE`, `DROP`, `ALTER`, `GRANT`, `SUPER`, and `FILE`.

How often should I update MySQL to stay secure?

Apply MySQL security patches promptly. Check the vendor’s release notes and apply any minor version updates or security releases within a few weeks of publication. Regularly schedule monthly checks for new MySQL releases and plan updates during maintenance windows.

Want a person to look at it?

Tell us what you see. We reply with what we think is wrong and what it would take to fix it.