2

I use the mysql command line client frequently. Sometimes I wind up typing in my password dozens of times per day, and I'm getting really tired of it.

SSH has a neat utility called ssh-agent which lets you type in your password just once at the beginning of the day. Is there a similar utility for MySQL?

Will Martin
  • 2,381
  • 5
  • 18
  • 18

3 Answers3

5

Create a ~/.my.cnf file in your $HOME with below content:

[mysql]
user     = root
password = pa$$w0rd
host     = mysql.server.ip.address

and make it can be readable by only you:

chmod 600 ~/.my.cnf
quanta
  • 50,327
  • 19
  • 152
  • 213
5

No. However, you can store your password in a my.cnf file in your home directory. For example, on linux

$ cat ~/.my.cnf
[client]
password="password"

You can also store user and host there. These options will be used by all mysql clients unless you override them. If you often connect to the same server with the same credentials, setting these can save you a lot of typing.

You need to make sure that your my.cnf is only readable by your user. For example, chmod 600 ~/.my.cnf.

sciurus
  • 12,493
  • 2
  • 30
  • 49
1

Yes, there is. Run the following, and type your password.

mysql_config_editor set --host=putYourHostHere --user=putYourUsernameHere --password
Marcel Br
  • 11
  • 1