Skip to content

Sinclert/mysql-shell-client

 
 

Repository files navigation

MySQL Shell Python client

CI/CD Status Coverage Status Apache license

MySQL Shell is an advanced client for MySQL Server that allow system administrator to perform both cluster and instance level operations, using a single binary.

This project provides a Python client to perform the most common set of operations, in addition to a set of predefined queries to cover most of the common use-cases.

🧑‍💻 Usage

  1. Install MySQL Shell.

  2. Install the package from PyPi:

    pip install mysql-shell-client
  3. Import and build the executors:

    from mysql_shell.executors import LocalExecutor
    from mysql_shell.models import ConnectionDetails
    
    cluster_conn = ConnectionDetails(
        username="...",
        password="...",
        host="...",
        port="...",
    )
    instance_conn = ConnectionDetails(
        username="...",
        password="...",
        host="...",
        port="...",
    )
    
    cluster_executor = LocalExecutor(cluster_conn, "mysqlsh")
    instance_executor = LocalExecutor(instance_conn, "mysqlsh")
  4. Import and build the query builders [optional]:

    from mysql_shell.builders import CharmLockingQueryBuilder
    
    # This is just an example
    builder = CharmLockingQueryBuilder("mysql", "locking")
    query = builder.build_table_creation_query()
    rows = instance_executor.execute_sql(query)
  5. Import and build the clients:

    from mysql_shell.builders.quoting import StringQueryQuoter
    from mysql_shell.clients import MySQLClusterClient, MySQLInstanceClient
    
    quoter = StringQueryQuoter()
    
    cluster_client = MySQLClusterClient(cluster_executor, quoter)
    instance_client = MySQLInstanceClient(instance_executor, quoter)

🔧 Development

Dependencies

In order to install all the development packages:

poetry install --all-extras

Linting

All Python files are linted using Ruff, to run it:

tox -e lint

Testing

Project testing is performed using Pytest, to run them:

tox -e unit
export MYSQL_DATABASE="test"
export MYSQL_USERNAME="root"
export MYSQL_PASSWORD="root_pass"
export MYSQL_SHELL_PATH="mysqlsh"

sudo --preserve-env docker compose -f compose/mysql-8.0.yaml up --wait && tox -e integration
sudo --preserve-env docker compose -f compose/mysql-8.0.yaml down

Release

Commits can be tagged to create releases of the package, in order to do so:

  1. Bump up the version within the pyproject.toml file.
  2. Add a new section to the CHANGELOG.md.
  3. Commit + push the changes.
  4. Trigger the release workflow.

About

Package to interact with MySQL Shell

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%