{"id":1148,"library":"apache-airflow-providers-mysql","title":"Apache Airflow MySQL Provider","description":"The Apache Airflow MySQL Provider enables seamless interaction with MySQL databases within Airflow DAGs. It offers operators and hooks to execute SQL queries, transfer data, and manage connections. As part of the Airflow ecosystem, it receives regular updates, with the current version being 6.5.1, requiring Python >= 3.10.","status":"active","version":"6.5.1","language":"en","source_language":"en","source_url":"https://github.com/apache/airflow/tree/main/airflow/providers/mysql","tags":["airflow","provider","mysql","database","sql"],"install":[{"cmd":"pip install apache-airflow-providers-mysql","lang":"bash","label":"Install the MySQL Provider"},{"cmd":"sudo apt-get install default-libmysqlclient-dev # For Debian/Ubuntu\n# Or for older Debian: sudo apt-get install libmysqlclient-dev","lang":"bash","label":"System dependencies for mysqlclient (if build errors occur)"}],"dependencies":[{"reason":"Core Airflow functionality; provider versions require specific Airflow versions (e.g., >=2.1.0, and >=2.2.0 for provider 3.0.0+).","package":"apache-airflow","optional":false},{"reason":"Common Python client for MySQL; installed as a dependency. Might require system-level development packages.","package":"mysqlclient","optional":false},{"reason":"Alternative Python client for MySQL; installed as a dependency.","package":"mysql-connector-python","optional":false}],"imports":[{"symbol":"MySqlHook","correct":"from airflow.providers.mysql.hooks.mysql import MySqlHook"},{"note":"`MySqlOperator` was removed in provider versions 6.3.2+; use `SQLExecuteQueryOperator` from the `common.sql` provider instead.","wrong":"from airflow.providers.mysql.operators.mysql import MySqlOperator","symbol":"SQLExecuteQueryOperator","correct":"from airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator"},{"symbol":"MySqlToS3Operator","correct":"from airflow.providers.mysql.operators.mysql import MySqlToS3Operator"}],"quickstart":{"code":"from __future__ import annotations\n\nimport pendulum\n\nfrom airflow.models.dag import DAG\nfrom airflow.providers.common.sql.operators.sql import SQLExecuteQueryOperator\n\n# Ensure you have a MySQL connection named 'mysql_default' configured in Airflow UI\n# Host: localhost, Schema: airflow_db, User: airflow, Pass: airflow\n\nwith DAG(\n    dag_id=\"mysql_quickstart_dag\",\n    start_date=pendulum.datetime(2023, 1, 1, tz=\"UTC\"),\n    catchup=False,\n    schedule=None,\n    tags=[\"mysql\", \"example\"],\n) as dag:\n    create_table = SQLExecuteQueryOperator(\n        task_id=\"create_test_table\",\n        conn_id=\"mysql_default\",\n        sql=\"\"\"\n            CREATE TABLE IF NOT EXISTS test_table (\n                id INT AUTO_INCREMENT PRIMARY KEY,\n                name VARCHAR(255)\n            );\n        \"\"\",\n    )\n\n    insert_data = SQLExecuteQueryOperator(\n        task_id=\"insert_test_data\",\n        conn_id=\"mysql_default\",\n        sql=\"INSERT INTO test_table (name) VALUES ('Airflow User 1'), ('Airflow User 2');\",\n    )\n\n    select_data = SQLExecuteQueryOperator(\n        task_id=\"select_test_data\",\n        conn_id=\"mysql_default\",\n        sql=\"SELECT * FROM test_table;\",\n    )\n\n    create_table >> insert_data >> select_data\n","lang":"python","description":"This quickstart demonstrates how to use `SQLExecuteQueryOperator` to interact with a MySQL database. It creates a table, inserts data, and then selects it. Ensure you have a MySQL connection named `mysql_default` configured in your Airflow UI."},"warnings":[{"fix":"Replace `MySqlOperator` imports and usages with `SQLExecuteQueryOperator`. The `conn_id` and `sql` parameters remain the same, and schema can be passed via `hook_params={'schema': '<database>'}`.","message":"The `MySqlOperator` was removed from the provider package. Users should migrate to `SQLExecuteQueryOperator` from `airflow.providers.common.sql.operators.sql` for executing SQL queries. This change was introduced in provider versions 6.3.2 and later.","severity":"breaking","affected_versions":">=6.3.2"},{"fix":"Ensure your Airflow installation meets the minimum version requirement for the MySQL provider you intend to install. Upgrade Airflow if necessary before installing the provider.","message":"Older versions of the MySQL provider (e.g., 2.x and above) require Apache Airflow version 2.1.0+ due to the removal of the `apply_default` decorator. Provider version 3.0.0+ specifically requires Airflow 2.2.0+. Installing an incompatible provider version may lead to automatic Airflow upgrades and require manual database migration.","severity":"breaking","affected_versions":"<6.x (for Airflow 2.1+ compatibility); <3.0.0 (for Airflow 2.2+ compatibility)"},{"fix":"Always install the provider package using `pip install apache-airflow-providers-mysql` in your Airflow environment.","message":"Attempting to import MySQL-related components like `MySqlOperator` or `MySqlHook` without explicitly installing `apache-airflow-providers-mysql` will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Before installing the Python package, install the necessary system-level development headers for MySQL. For Debian/Ubuntu, use `sudo apt-get install default-libmysqlclient-dev`.","message":"Installation of the `mysqlclient` dependency can fail if required system-level development packages (e.g., `libmysqlclient-dev` on Debian/Ubuntu) are not present, leading to build errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that `apache-airflow-providers-common-sql` is constrained to a compatible version or upgrade `apache-airflow-providers-mysql` to its latest version, which usually resolves such conflicts.","message":"Users have reported `AttributeError: property 'connection' of 'MySqlHook' object has no setter` when `apache-airflow-providers-mysql` has no upper version constraint on `apache-airflow-providers-common-sql`, leading to incompatible versions being installed.","severity":"gotcha","affected_versions":"Certain combinations with `apache-airflow-providers-common-sql <1.17.0` (e.g., `apache-airflow-providers-mysql 5.6.1` with `apache-airflow-providers-common-sql 1.17.0`)"},{"fix":"For persistent connections, consider enabling connection pooling with recycling. Adjust MySQL server's `wait_timeout` and `interactive_timeout` parameters if applicable.","message":"Long-running MySQL connections via Airflow can experience 'Server has gone away' errors, typically due to the MySQL server restarting or connection timeouts.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-06T21:57:43.893Z","next_check":"2026-07-04T00:00:00.000Z"}