It can be painful to copy/paste your mysql password each time your want to login into your MySQL server, and it’s not recommended to put the password directly in your command because it will be displayed in clear text in the process list, and another user may be able to get your password.
Set your credentials in .my.cnf
There is a simple solution to login automatically, it’s to set your credentials in a file named .my.cnf in your user’s home directory.
Create the file .my.cnf
And set your MySQL credentials like in the following example :
[client] user = root password = X7x7x7X6S4z
Then just use the command
mysql to login into MySQL instead of
mysql -u root -p.
It also provide you the ability to use the other commands available with mysql-client like