Software >> Services >> RDBMS >> MySQL >> Command Line >> How to run mysql from command line without being prompted for password using .my.cnf

in the user's home directory, create

.my.cnf

with following entries

 

[client]
# for local server use localhost
host=mysqlhost
user=mysqluser
password=mysqlpassword
 
[mysql]
pager=/usr/bin/less

e.g. for login using root to the mysql on localhost use

[client]
# for local server use localhost
host=localhost
user=root
password=mysqlpassword
 
[mysql]
pager=/usr/bin/less