MySQL Shell 9.1  /  ...  /  Persisting Extension Objects

10.2.3 Persisting Extension Objects

A script to define and register extension objects must have a file extension of .js for JavaScript code, or .py for Python code, to match the language used for the script. The file extension is not case-sensitive.

The preferred way to persist an extension object is by adding it into a MySQL Shell plugin. Plugins and plugin groups are loaded automatically when MySQL Shell starts, and the functions that they define and register are available immediately. In a MySQL Shell plugin, the file containing the initialization script must be named init.js or init.py as appropriate for the language. 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 instructions to use MySQL Shell plugins, see Section 10.3, “MySQL Shell Plugins”.

As an alternative, scripts containing extension objects can be stored directly in the init.d folder in the MySQL Shell user configuration path. When MySQL Shell starts, all files found in the init.d folder with a .js or .py file extension are processed automatically and the functions that they register are made available. (In this location, the file name does not matter to MySQL Shell.) The default MySQL Shell user configuration path is ~/.mysqlsh/ on Unix and %AppData%\MySQL\mysqlsh\ on Windows. The user configuration path can be overridden on all platforms by defining the environment variable MYSQLSH_USER_CONFIG_HOME.