I'd like to write a command line script for Debian, what secures a MySQL installation, just like mysql_secure_installation.
Do you know any way to either: emulate user inputs to mysql_secure_installation, thus make it run inside a script or to replicate the functionality by SQL statements?
Here is how far I came:
Remove anonymous users: (users with no password) idea:
DROP USER ''@'localhost';
DROP USER ''@'host_name';
problem: I don't know host name in a script file, would be better with where password = '', but I don't know how to combine it with drop user.
DELETE FROM user WHERE user = '';
does it, but AFAIK, it doesn't remove privileges. I'd better use DROP USER for this.
Disallow root login remotely:
I think it is to remove the root user, what's host isn't "localhost", "127.0.0.1" or "::1"
Any idea how to do this? A stronger alternative is to have skip-networking in the config file:
[mysqld]
# Prevent network access to MySQL.
skip-networking
Remove test database and access to it:
DROP DATABASE test;
What do I need to do to remove privileges on the test database? Isn't this enought?
Finally, flusing the priviliges:
FLUSH PRIVILEGES;
References
http://dev.mysql.com/doc/refman/5.6/en/mysql-secure-installation.html
http://dev.mysql.com/doc/refman/5.6/en/default-privileges.html