Access mysql/mysqldump without password entry each time - Using .my.cnf
Access mysql/mysqldump without password entry each time - Using .my.cnf
In this guide we will show you have to save your mysql credentials so you do not have to enter them each time run mysql or mysqldump.
This is done by creating a ~/.my.cnf file in your users home directory.
vim /home/bnelson/.my.cnf or vim ~/.my.cnf
After you have created this file you can enter your credentials.
[client] user=mysqluser password=mysqlpass
- It is best to use a superuser for this, so that you can have access to all databases.
If you are attempting to create a script to do a mysql dump or optimization, this will allow you run that script without having it stop and wait for credentials.
Overview and Thoughts
For safety, make this file readable to you only by running chmod 0600 ~/.my.cnf
Of course, if you specify username and password explicitly as part of commands arguments, they will be used.
Next time you run mysql commands mysql, mysqlcheck, mysqdump, etc; they will pick username & password from this file if you do not provide them as argument (-u and -p).