MySQL Shell 9.5  / ...  / Customizing MySQL Shell  / Adding Module Search Paths  /  Module Search Path Variable in Startup Scripts

14.2.2 Module Search Path Variable in Startup Scripts

Thesys.path variable can be customized using the MySQL Shell startup scriptmysqlshrc.js for JavaScript mode ormysqlshrc.py for Python mode. For more information on the startup scripts and their locations, seeSection 14.1, “Working With Startup Scripts”. Using the startup script, you can append module paths directly to thesys.path variable.

Note that each startup script is only used in the relevant language mode, so the module search paths specified inmysqlshrc.js for JavaScript mode are only available in Python mode if they are also listed inmysqlshrc.py.

For Python modify themysqlshrc.py file to append the required paths into thesys.path array:

# Import the sys moduleimport sys# Append the additional module pathssys.path.append('~/custom/python')sys.path.append('~/other/custom/modules')

For JavaScript modify themysqlshrc.js file to append the required paths into thesys.path array:

// Append the additional module paths  sys.path = [...sys.path, '~/custom/js'];  sys.path = [...sys.path, '~/other/custom/modules'];

A relative path that you append to thesys.path array is resolved relative to the current working directory.

The startup scripts are loaded when you start or restart MySQL Shell in either JavaScript or Python mode, and also the first time you change to the other one of those modes while MySQL Shell is running. After this, MySQL Shell does not search for startup scripts again, so implementing updates to a startup script requires a restart of MySQL Shell if you have already entered the relevant mode. Alternatively, you can modify thesys.path variable at runtime, in which case therequire() orimport function uses the new search paths immediately.