How To Connect MySQL Server Without Password Prompt

connect-mysql-server-without-prompting-password
mm
Written By:- Santosh Prasad

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.

Thanks:)

About Author

mm

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.

Other Post by Santosh Prasad

Visit All Post

Related Article

You may also Like

Leave a Comment

Shares