Keep your passwords secure

Sep 24, 2007 14:11 GMT  ·  By

The first way to keep your password secure is to secure the user grant table and never give access to it to users that aren't in the administrative group. Another way to secure your password is to prevent running programs that connect to your SQL server and users can see the password through that program.

To prevent that, use the following options: -pyour_pass or --password=your_pass . So, your sql statement will look like this: shell> mysql -u root -ppass db_name. You may use this statement because it is very easy to remember, but is relatively insecure. Users can see the password if they have access to system status programs. Almost all MySQL clients overwrite the command-line password argument with zeros during their initialization sequence, but there is a fraction of second when the password is visible.

A solution for this is to use the following statement: shell>mysql -u root -p db_name. This way you will be asked to enter separately the password and the characters from the password will be changed with "*" so nobody can decipher your password. The problem with this method is that it is suitable with interactive programs. If you want to invoke a program from a non-interactive script, there is no way to enter the password.

Another way to keep your password secure is to enter the my.cnf file. You will have to enter it in [client] section of the file: [client] password=your_password

In Unix environment chmod is the file to access mode 400 or 600.

The last method you can use is to store your password in the MYSQL_PWD environment variable. But this method is the most insecure one. Again, users that have access to system status programs can see the password.

After presenting the methods, I recommend you to use the configuration file. This is the most secure way to hide your password.