MySQL Hardening Starts with the Accounts Your Application Uses

Image retained from the original article.

Originally published 21 July 2023; rewritten and reviewed on 15 October 2026.

It is tempting to configure a new VPS, install MySQL, create a user with GRANT ALL PRIVILEGES ON *.*, plug it into .env, and celebrate because the site loads. Everything works on day one, so nobody touches it again.

The problem is that convenience quietly hands your web application—and any future SQL injection bug or leaked config file—full administrative authority over every database on the server. Good MySQL hardening does not start with obscure my.cnf flags; it starts with network exposure, account boundaries, and knowing you can actually restore your data.

Shrink the Network Surface First

Before tuning anything inside SQL, decide who is actually allowed to reach port 3306. If your PHP, Node.js, or ASP.NET app runs on the same Linux server as MySQL, there is no reason for MySQL to listen on 0.0.0.0.

In /etc/mysql/mysql.conf.d/mysqld.cnf, keep bind-address = 127.0.0.1. If your app server sits on a separate host, bind MySQL to the private VPC or WireGuard/Tailscale interface rather than the public IP, and lock down ufw or your cloud security group so only the application server’s IP can connect on 3306.

When remote connections over a network are unavoidable, enforce encrypted transport (require_secure_transport = ON) so credentials and query payloads are never sent in plaintext. Also disable local_infile = 0 unless a specific import job genuinely requires it, reducing the risk of arbitrary local file reads if an attacker ever gains query execution.

Keep MySQL on a supported LTS/major release and apply security updates on a schedule, after testing compatibility on staging. Specific version numbers from 2023 blog posts age quickly; what matters is staying within an actively patched branch.

Separate Application Accounts from Migration Accounts

Most web applications only need to read and write rows during normal HTTP requests. They do not need DROP TABLE, ALTER, SUPER, or FILE privileges.

Create a dedicated runtime user restricted to the specific database and host it connects from, and give it only the privileges normal traffic requires:

-- Runtime account: data access only, no schema changes
CREATE USER 'app_runtime'@'10.0.1.%' IDENTIFIED BY 'strong-random-password';
GRANT SELECT, INSERT, UPDATE, DELETE ON app_db.* TO 'app_runtime'@'10.0.1.%';

-- Verify what the account can actually do
SHOW GRANTS FOR 'app_runtime'@'10.0.1.%';

Keep schema migrations (CREATE, ALTER, INDEX, DROP) under a separate deployment account used only during CI/CD or maintenance windows. That way, even if a vulnerable WordPress plugin or custom API endpoint is compromised, the attacker cannot trivially wipe tables or alter user-privilege tables outside app_db.

Never reuse the root account in application config files, and never paste real credentials into diagnostic logs or error pages.

Backups, Restore Drills, and Visibility

Hardening is incomplete if a bad migration or ransomware incident still leaves you unable to recover. Automated mysqldump or physical snapshots are only half the job—an untested backup is just an assumption.

Make sure your backup workflow covers three basics:

  • Run consistent dumps (mysqldump --single-transaction --routines --triggers) using a dedicated read-only backup user, and store the encrypted output off-server (for example, in object storage with restricted bucket permissions).
  • Periodically test restoring a dump onto a disposable staging instance and verify that the application boots and reads the data cleanly.
  • Keep error logs and slow-query logs enabled and rotated so unusual connection spikes, repeated failed logins, or sudden table locks are visible instead of silent.

A hardened MySQL server should still be straightforward for your team to operate. Document which accounts exist, why each host is allowlisted, and how a restore works—that clarity beats copying a random 50-line security checklist from the internet.