When running a batch file on MySQL the login credentials must be taken from some file. The file choices are to use a clear-text options file or the more secure obfuscated login-file generated by the MySQL program mysql_config_editor (which comes installed with the MySQL Community edition). The documentation for the mysql_config_editor can be found at https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html (MySQL V. 8.0). Provided here is an example of mysql_config_editor being used.
The starting point for this example will be to mention that the MySQL installation does not automatically add a .mylogin.cnf file into your directory (Figure 1).
Next, even though the default login-path will be “client” there does not automatically exist a login-path with that name (Figure 2).
The print –all statement will come up again later in the example. For now, it’s important to note that it doesn’t return anything.
The Set Command
Now that some setup has been taken care of, the example can continue with creation of the first login-path. From the MySQL documentation it is known the program command format is as follows:
“mysql_config_editor set –login-path=LoginPathName –host=HostName –user=UserName –password ”
where additional options such as –port –socket and –help can be included.
The example in Figure 3 uses the above format. For the first login-path “client” is used, which will be what the mysql client program defaults to when no login-path is provided.
When the mysql_config_editor program is run with the “set” command for the first time, a .mylogin.cnf file is generated (Figure 3).
For this example, a second login-path will be created with the name “someLoginPath” as a generic stand-in label.
The Print Command
Now the “print” command can be used to view all stored login-paths when paired with the –all option (Figure 5).
Alternatively, should only a particular login-path be required the “print” command can be passed with a specific login-path as shown in Figure 6.
In order to confirm that the .mylogin.cnf file is not a clear-text file it can be opened with any text editor. The results for this example’s obfuscated .mylogin.cnf file are shown in Figure 7. The .mylogin.cnf file in Figure 7 is definitely not a clear-text file.
The Remove Command
Should a need to overwrite a login-path arise, this can be done one of two ways. The first is to run the “set” command with the new information which will overwrite the original contents of the passed login-path (Figure 8). The other way to change a login-path is by using the “remove” command passing the login-path name as an option along with any desired changes; this will remove any passed options from the login-path. If no options other than login-path are passed, the entire login-path is removed (Figure 9). After the removal of a login-path it will have to then be recreated using the “set” command.
The Reset Command
In order to remove all login-paths the “reset” command is used. This will remove all login-paths from the .mylogin.cnf file, however the file will still exist (Figures 10 and 11).
The Help Command and Option
The order of the help command matters. It can be passed as an option to any of the mysql_config_editor commands, or as an option to the mysql_config_editor (See Figures 12 – 14).