Connecting to MySQL from localhost without entering a password

Suppose you need to make the user root can connect to MySQL from localhost without entering a password.

To do this, create the MySQL configuration file in the home directory of the user you are connecting from (in the nano text editor, press CTRL + X to exit, y / n to save or cancel changes):

sudo nano ~/.my.cnf

For security purposes, we will configure access to the .my.cnf file only for the root user of the system.

sudo chown root:root ~/.my.cnf
sudo chmod 400 ~/.my.cnf

And add the client section, specifying the user’s login and password in it, as well as several other parameters:


Let’s try to connect, immediately the MySQL console should appear (without requesting a password):

Подписаться на IT Blog (RU) по Email
Subscribe to IT Blog (EN) by Email

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a Reply