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.

user = myuser
password = secret

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.


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment