Securing a MySQL database is critical to protect sensitive data from unauthorized access, data breaches, or malicious attacks. Implementing robust security measures reduces the risk of vulnerabilities.
Ensure all MySQL user accounts, especially the root account, have strong, complex passwords.
By default, the MySQL root user has full privileges. Allowing remote root access poses a significant security risk.
Open MySQL:
mysql -u root -p
Check root access:
SELECT User, Host FROM mysql.user WHERE User = 'root';
Update root's access to localhost:
UPDATE mysql.user SET Host = 'localhost' WHERE User = 'root';
Flush privileges:
FLUSH PRIVILEGES;
Use SSL/TLS to encrypt client-server connections, ensuring that data in transit is secure. This is especially important for remote connections to the MySQL server.
[mysqld]
ssl-ca=/path/to/ca-cert.pem
ssl-cert=/path/to/server-cert.pem
ssl-key=/path/to/server-key.pem
ALTER USER 'username'@'host' REQUIRE SSL;
sudo systemctl restart mysql