August 16, 2014 · database hacks linux mysql newbie security server shell

Secure New MySQL Installation


After installing MySQL, it's important that you secure the installation by

a) removing anonymous accounts and
b) setting a password on the admin account.

This can be done with mysqladmin or with direct SQL queries. I prefer the SQL queries so that's what I'll show here.

  1. Start mysql command line utility and select the mysql database.
  2. Remove anonymous accounts.
  3. Set a password on the mysql root account.
  4. Flush privileges.
[root@localhost]# mysql 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 17073 
Server version: 5.5.27 Distributed by The IUS Community Project 
mysql> delete from user where user = ""; 
Query OK, 2 rows affected (0.00 sec) 
mysql> update user set password = PASSWORD('aStrongPassword'); 
Query OK, 4 rows affected (0.00 sec) 
Rows matched: 4 
Changed: 4 
Warnings: 0 
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec) 
mysql> quit; 
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket