How to do it...

Create the .mylogin.cnf file using mysql_config_editor:

shell> mysql_config_editor set --login-path=dbadmin_local --host=localhost --user=dbadmin --passwordEnter password:

You can add multiple hostnames and passwords by changing the login path. If the password is changed, you can run this utility again, which updates the password in the file:

shell> mysql_config_editor set --login-path=dbadmin_remote --host=35.186.157.16 --user=dbadmin --passwordEnter password: 

If you want to log in to 35.186.157.16 using the dbadmin user, you can simply execute mysql --login-path=dbadmin_remote:

shell> mysql --login-path=dbadmin_remote Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 215074~mysql> SELECT ...

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.