Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

closed as not a real question by Randolph West, Indrek, Canadian Luke, Nifle, 8088 Sep 11 '12 at 1:06

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Hi zsero. I think your question is too broad at the moment. Please edit it to be more specific, otherwise it will most probably be closed. –  user3463 Sep 10 '12 at 0:42
    
I've done it in Python in the meantime. pastebin.com/b4twn5YK I think it would be very difficult using just SQL commands. You can close the question, if someone finds it he can find the solution in this comment. –  zsero Sep 10 '12 at 1:10
add comment

1 Answer

up vote 0 down vote accepted

There are two things you must be made aware of

OBSERVATION #1

While the other steps you outlined above are good, you forgot one more thing that's not really documented anywhere: You must remove test entries from the mysql.db table. I'll repeat myself: It is not documented anywhere. In fact, I wrote about this problem in the DBA StackExchange. I wrote an additional answer along these lines back on Feb 17, 2012.

OBSERVATION #2

You should not use skip-networking if you plan to use external web servers or MySQL Replication.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.