Securing Mysql

1. Restrict anonymous remote access :- Which means never provide grant access from all hosts. It must limit to specific users from specific hosts only. Do not grant the SUPER privilege and FILE privilege to non-administrative users. Any user who has this privilege can write a file anywhere in the file system with the privileges of the mysqld daemon.



in “/etc/my.cnf”

This line disables the initiation of networking during MySQL startup. Please note that a local connection can still be established to the MySQL server.


Another possible solution is to force MySQL to listen only to the localhost by adding the following line in the[mysqld] section of my.cnf


2. Improve local security :- To improve local security use different socket file for both client and server connections. For that edit and add following line in the [client] section of /etc/my.cnf:


socket = /tmp/mysql.sock

Also the following parameter should be added in the [mysqld] section in /etc/my.cnf:


3.  Change admin password :- This is the most important step in securing MySQL is changing the database administrator’s(root) password, which is empty by default. Below are the steps to change administrator password.

mysql -u root mysql> SET PASSWORD FOR root@localhost=PASSWORD(‘new_password’);

4. Change admin name :- It is strongly recommending to change the default name of administrator’s account (root), to a different for the more security. Such a change will help to prevent from the brute-force and dictionary attacks on the administrator’s password.

mysql> update user set user=”mysqluser” where user=”root”; mysql> flush privileges;


5. Remove history :- We also recommended to remove the content of the MySQL history file (~/.mysql_history, ~/.history, ~/.bash_history,~/.mysql_history) in which having all executed SQL commands (especially passwords are stored in this as plain text).


6. User Access Privileges :- Create accounts for specific databases which will be used by specific applications, so accounts should have access rights only to the databases which are used by the specific applications. In particular,they no longer will have any access rights to the mysql database, nor any system or administrative privileges (FILE, GRANT, ALTER, SHOW DATABASE, RELOAD, SHUTDOWN, PROCESS, SUPER etc.). Any Application user should not granted all privileges to database with Grant option from any host.


7. Disable remote access :- Only few applications on the same server will be allowed to access the database. So we need MySQL not to even listen on port 3306 for TCP connections like it does by default.

Edit /etc/my.cnf and uncomment the skip-networking line (comment the leading #).

8. Remove default users/db :- Remove the sample database (test) and all accounts except the local root account:

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 is why because it will prevent the database from establishing anonymous connections and irrespective of the skip-networking parameter in /etc/my.cnf remote connections as well.

Tagged , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: