Skip to content

MySQL

Since testcontainers-python v4.6.0

Introduction

The Testcontainers module for MySQL.

Adding this module to your project dependencies

Please run the following command to add the MySQL module to your python dependencies:

pip install testcontainers[mysql] sqlalchemy pymysql

Usage example

import sqlalchemy



from testcontainers.mysql import MySqlContainer





def basic_example():

    config = MySqlContainer("mysql:8.3.0", dialect="pymysql")



    with config as mysql:

        connection_url = mysql.get_connection_url()



        engine = sqlalchemy.create_engine(connection_url)

        with engine.begin() as connection:

            result = connection.execute(sqlalchemy.text("select version()"))

            for row in result:

                print(f"MySQL version: {row[0]}")