Print

Locking Down MySQL

This document describes basically how to lock down a MySQL server. It should be your first step in setting up a database server!


Change database administrators password:
mysql> SET PASSWORD FOR root@localhost=PASSWORD('new_password')


Remove sample database:
mysql> DROP DATABASE test;


Drop all users and databases we don't need:
mysql> USE mysql;
mysql> DELETE FROM db;
mysql> DELETE FROM user WHERE NOT (host="localhost" AND user="root");
mysql> FLUSH PRIVILEGES;


Change admin username:
mysql> UPDATE user SET user="mydbadmin" WHERE user="root";


Finishing Up:
Remove the mysql command history as we gave the admin password above, this is saved in the command history in plain text.
# rm -f ~/.mysql_history



Copyright © 2000-2009, AllWorldIT
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
The registered trademark Linux® is used pursuant to a sublicense from LMI, the exclusive licensee of Linus Torvalds, owner of the mark on a world-wide basis.