DEV Community

Discussion on: How to securely login to MySQL without providing password each time

Collapse
 
bobbyiliev profile image
Bobby Iliev

Hi there 👋,

Very good question.

Yes, this is doable, you can specify a host and then have a suffix for each host in your config file.

Example:

  • DB Host 1:
[clientdb1]
user=your_username
password=your_pass
host=db1.example.com
Enter fullscreen mode Exit fullscreen mode

Note the client + db1 suffix, then to specify which SQL server you would like to connect to you need to use the --defaults-group-suffix= flag, for the above example it will look like this:

mysql --defaults-group-suffix=db1
Enter fullscreen mode Exit fullscreen mode

To make things easier, you could also add a Bash alias for that command so that you don't have to type the whole thing each time.

Hope that this helps!

Collapse
 
darshitpp profile image
Darshit Patel

Thanks for the reply! I will try this out