How To Connect MySQL Server Without Password Prompt
There are lots of questions like, how do I use MySQL command without prompting password? How can I use mysqldump command without using the password in the script? How can I use MySQL commands without passing the password in crontab?
In this article, I will describe how you can use MySQL command without prompting password.
1. Create a file called .my.cnf in users home directory from which command or script to run.
# vim ~/.my.cnf
Add the below content into this file and change username and password as per your system configuration.
[mysql] user = myuser password = secret [mysqldump] user = myuser password = secret
2. Now secure your .my.cnf file.
# chmod 600 ~/.my.cnf
3. Now everything is done. Lets go for testing.
# mysql -h localhost/remote_server -u mysql_user # mysqldump -h localhost/remote_server -u mysql_user --all-databases > alldb_bkp.sql
Above I have used two commands to verify the configuration. First command is used to login to MySQL server without prompting password and second command is used to take backup all your databases without password.
You can also used MySQL commands in any shell scripts or schedule crontab for backup.