mysql -u root -p
Enter the password (Press enter if the root password is blank).
Step 1: Removing test databases
mysql> drop database test;
mysql> use mysql;
mysql> delete from db;
mysql> delete from user where not (host="localhost" and user="root");
mysql> flush privileges;
This will remove all other databases that are not root.
Step 2: Set a strong root password (Root password is empty by default)
mysql> UPDATE mysql.user SET Password = PASSWORD('astrongpassword’)
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
Step 3: Disable remote access to MySQL
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf
skip-networking
You can still remotely access the database using ssh, so don’t worry about it.
Additional security tips:
Set a strong root password: I cannot emphasize this enough. Setting a root password isn’t everything. You need a password that is hard to decipher. Try generating a random password from the command line with the following code:
$ date | md5sum
Don’t use MySQL as root: Create a separate user and then use it to test, modify and add databases. Avoid logging in as root as much as possible.
Lockdown the data directory: Change the permission of the directory where database is stored so that only selected users can access it. You can do that using chown and chmod commands.
Periodically backup MySQL data: Even though the server might be relatively immune to attacks, it’s still a good idea to backup your databases. You can use the mysqldump command to do that.
Here’s a sample of the command in action:
mysql --u [username] --password=[password] [database name] < [dump file]
No comments
Post a Comment