Managing MySQL Shell Configuration Options

Over the last few years, I have become quite smitten with MySQL Shell. For those who may not be familiar with MySQL Shell, it is a new(ish) command line interface (CLI) for connecting to and managing MySQL instances. During a recent episode of Inside MySQL: Sakila Speaks, Fred and I talked to Miguel Araujo about many of the helpful (and lesser known) features of MySQL Shell. This post is the seventh in a series about these “hidden gem” features.
The Problem
As with any tool, the out-of-the-box configuration for MySQL Shell might not fit the needs or desires of every user in every situation. We need a way to easily view, update, and persist (if necessary) changes to the default configuration.
The Solution
If you have been reading my other posts about some hidden gems in MySQL Shell, you have already figured out we have a command to help us manage our MySQL Shell configuration. That command is \option
.
Listing Options
We can list the options available to us by using the command:
In version 8.4 of MySQL Shell, the output from this command will resemble the following:
Since I have already updated some of these options, your values may differ.
Check out the documentation for more details on these options and possible values.
Updating the Configuration
The syntax for updating configuration values is as follows:
Or
Let’s assume that we need to change the value of the verbose
from 0
to 4
while troubleshooting an issue. We can change this value by executing the command:
When we run \option -l
again, we will see the value of verbose
was updated to 4
.
When we update configuration values using this command syntax, the value is only updated for the session. If we were to quit MySQL Shell and start it again, the’ verbose’ value would revert to 0
.
Persisting an Update
Until version 8.4 of MySQL Shell, it wou8ld start in JavaScript by default. As of version 8.4, MySQL Shell starts in SQL mode. I use JavaScript mode more frequently, so I want to update my configuration to set the value of the defaultMode
option to js
and have this change persist across sessions. The syntax to save the configuration update to the local config file so it can persist across sessions is:
So, to update the defaultMode
value and have it saved to the local configuration file, we would use this command:
Let’s verify the change by running \option -l
.
Checking Source of Values
We can view where the value got its value by using the follwoing command:
The output will resemble the text below.
We can see that many of the values are Compiled default
, some are Configuration file
, and one is Environment variable
. Note that the value of defaultMode
shows the value came from the configuration file. This message is because I restarted MySQL Shell after changing the value to js
. If I had not restarted MySQl Shell, it would show the origin as User defined
. Any value that we change but do not persist will also show as User defined
.
Revert to Default Values
If we made a configuration change and wanted to revert the value to the default, we would use the following syntax to revert an option to its default value.
or
Both of these commands will revert the option’s value to the default for the current session. The second example will remove the option value from the MySQL Shell configuration file.
To revert the defaultMode
to the default value and remove this from the configuration file, we run the command:
When we run \option -l --show-origin
, we will see output similar to:
The value of defaultMode
is now none
and we can see that value was a compiled default value.
Wrap-Up
MySQL Shell has multiple configuration options to fit different situations and different user preferences. Using the \option
command, we can view and manage these configuration values. We can even persist these values across MySQL Shell sessions. If you want to learn more about updating the configuration for MySQL Shell, head on over to the documentation.
Related Entries
- Running External Scripts in MySQL Shell
- Executing System Commands in MySQL Shell
- Getting Help in MySQL Shell
- Sandboxes in MySQL Shell
- Server Upgrade Checks with MySQL Shell
- MySQL Connection Status with MySQL Shell
- Advanced Data Dump with MySQL Shell
- Advanced Data Load with MySQL Shell
- MySQL Shell CLI Integration
- MySQL Shell Table Export Utility
- Copy Data Directly To A MySQL Instance With MySQL Shell
- Create an InnoDB Replica Set With MySQL Shell
- Using MySQL Shell to Get MySQL Diagnostic Information
- Customizing The MySQL Shell Prompt
- Extending MySQL Shell with Startup Scripts
- Extending MySQL Shell with Plugins
- Doing a 'Incremental' Dump With MySQL Shell