{"id":28385,"library":"testcontainers-mysql","title":"testcontainers-mysql","description":"MySQL component of testcontainers-python, providing lightweight MySQL database containers for integration testing. Compatible with testcontainers core. Current version: 0.0.1rc1 (pre-release). Release cadence: follows testcontainers-python releases (monthly).","status":"active","version":"0.0.1rc1","language":"python","source_language":"en","source_url":"https://github.com/testcontainers/testcontainers-python","tags":["testcontainers","mysql","testing","docker","integration-test"],"install":[{"cmd":"pip install testcontainers-mysql","lang":"bash","label":"Install testcontainers-mysql"}],"dependencies":[{"reason":"Core library required; provides base container classes and Docker management.","package":"testcontainers","optional":false},{"reason":"Commonly used MySQL driver for connecting to the container.","package":"mysql-connector-python","optional":true},{"reason":"Alternative MySQL driver.","package":"pymysql","optional":true}],"imports":[{"note":"Hyphen in package name, underscore in module.","wrong":"from testcontainers_mysql import MySQLContainer","symbol":"MySQLContainer","correct":"from testcontainers.mysql import MySQLContainer"}],"quickstart":{"code":"from testcontainers.mysql import MySQLContainer\n\nwith MySQLContainer('mysql:8.0') as mysql:\n    connection_url = mysql.get_connection_url()\n    print(f\"Connection URL: {connection_url}\")\n    # Use the connection URL with a MySQL driver\n    import pymysql\n    conn = pymysql.connect(**mysql.get_connection_params())\n    cursor = conn.cursor()\n    cursor.execute(\"SELECT version();\")\n    print(cursor.fetchone())\n    conn.close()","lang":"python","description":"Start a MySQL 8.0 container, get connection parameters, and run a query."},"warnings":[{"fix":"Always specify an image tag: MySQLContainer('mysql:8.0').","message":"MySQLContainer requires a Docker image tag (e.g., 'mysql:8.0') as of v0.0.1rc1. Older versions may have used a default tag, which no longer works.","severity":"breaking","affected_versions":">=0.0.1rc1"},{"fix":"Use mysql.get_connection_params() for Python driver connections.","message":"get_connection_url() returns a JDBC-style URL (jdbc:mysql://...). Use get_connection_params() to get a dict suitable for Python drivers (pymysql, mysql-connector-python).","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure Docker is running and free ports are available. Use with statement for automatic cleanup.","message":"Container may fail silently if Docker is not running or if ports are occupied. Always check container logs or use wait_for() strategies.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"pip install testcontainers","cause":"testcontainers core package is not installed.","error":"ModuleNotFoundError: No module named 'testcontainers'"},{"fix":"Start Docker Desktop or run 'dockerd'; ensure user is in 'docker' group.","cause":"Docker daemon is not running or user lacks permissions.","error":"docker.errors.DockerException: Error while fetching server API version"},{"fix":"Use a recent and stable image like 'mysql:8.0'. Increase Docker memory allocation if needed.","cause":"Outdated or incompatible MySQL image specified, or memory constraints.","error":"testcontainers.mysql.container:error: MySQL container crashed on startup"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}