How to connect to MySQL using CLI without manually entering username and password

Clovon
Nov 17, 2021

Normally, to connect to MySQL using CLI we run the following command:

mysql -u root -p

Here we are manually specifying username as root and password as the one we entered. But, if we want to connect to MySQL without manually entering username and password then you can follow the following steps:

  1. You can use the mysql_config_editor command to set login path, host, username, and password by writing the following command on your terminal and pressing enter to enter your password:
$ mysql_config_editor set --login-path=client --host=localhost --user=root --password

2. Now if you just write mysql and press enter without specifying username and password then you will automatically get connected.

This can be helpful while you want to connect to MySQL instantly while working on your project locally.

You can also find the video explanation HERE.

--

--