I am writing the code in python to automate the innodb cluster provisioning. Based on this example https://dev.mysql.com/doc/dev/mysqlsh-api-python/8.0/group__mysql.html
mysql-py> from mysqlsh import mysql
// Then you can use the module functions and properties
// for example to create a session
mysql-py> mySession = mysql.get_classic_session('admin@localhost')
I was curious if there is a way to load mysqlsh module outside mysql shell.
For example
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from mysqlsh import mysql
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysqlsh'
The package you need is mysql-connector-python
Here's what worked for me:
Assuming you have sample datastore schema downloaded and imported world_x Database (You can get it from here)
pip3 install mysql-connector-python
>>> import mysqlx
Here's the full python snippet: