Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 463.0Kb
PDF (A4) - 459.7Kb
HTML Download (TGZ) - 92.3Kb
HTML Download (Zip) - 103.9Kb


MySQL Shell 8.0  /  ...  /  Creating MySQL Shell Plugins

6.3.1 Creating MySQL Shell Plugins

MySQL Shell plugins can be used to contain functions that are registered as MySQL Shell reports (see Section 6.1, “Reporting with MySQL Shell”), and functions that are members of extension objects that are made available by user-defined MySQL Shell global objects (see Section 6.2, “Adding Extension Objects to MySQL Shell”). A single plugin can contain and register more than one function, and can contain a mix of reports and members of extension objects. Functions that are registered as reports or members of extension objects by a MySQL Shell plugin are available immediately when MySQL has completed startup.

A MySQL Shell plugin is a folder containing an initialization script appropriate for the language (an init.js or init.py file). The initialization script is the entry point for the plugin. A plugin can only contain code in one language, so if you are creating an extension object with a mix of members defined in Python and members defined in JavaScript, you must store the members as separate language-appropriate plugins.

For a MySQL Shell plugin to be loaded automatically at startup, its folder must be located under the plugins folder in the MySQL Shell user configuration path. MySQL Shell searches for any initialization scripts in this location. MySQL Shell ignores any folders in the plugins location whose name begins with a dot (.) but otherwise the name you use for a plugin's folder is not important.

The default path for the plugins folder is ~/.mysqlsh/plugins on Unix and %AppData%\MySQL\mysqlsh\plugins in Windows. The user configuration path can be overridden on all platforms by defining the environment variable MYSQLSH_USER_CONFIG_HOME. The value of this variable replaces %AppData%\MySQL\mysqlsh\ on Windows or ~/.mysqlsh/ on Unix.

When an error is found while loading plugins, a warning is shown and the error details are available in the MySQL Shell application log. To see more details on the loading process use the --log-level=debug option when starting MySQL Shell.

When a MySQL Shell plugin is loaded, the following objects are available as global variables:

  • The built in global objects shell, dba, and util.

  • The Shell API main module mysql.

  • The X DevAPI main module mysqlx.

  • The AdminAPI main module dba.