Steve.Gao
Steve.Gao

Reputation: 297

airflow mysql_hook No module named 'MySQLdb'

I got

No module named 'MySQLdb'

when importing ariflow

from airflow.hooks.mysql_hook import MySqlHook

I'm using Mac, python 3.7.6

Installed

  1. pip install 'apache-airflow[mysql]'
  2. pip install apache-airflow
  3. PyMySQL==0.10.1
  4. marshmallow-sqlalchemy==0.23.1
  5. mysql-connector-python==8.0.22
  6. mysqlclient==1.3.14

Beside this specific issue, we have a server installed airflow and I was tring to test some airflow components (hooks etc) without full airflow environment, is that feasible?

Thanks!

Upvotes: 5

Views: 5208

Answers (1)

Elad Kalif
Elad Kalif

Reputation: 15961

You are not using the updated MySqlHook.

For Airflow <2.0 you will need to install backport providers :

pip install apache-airflow-backport-providers-mysql

For Airflow >=2.0 you will need to install providers:

pip install apache-airflow-providers-mysql

then you can import the hook via:

from airflow.providers.mysql.hooks.mysql import MySqlHook

As for your second question i'm not sure what you mean by full airflow environment. The providers for example were removed from Airflow core to separated packages.

Upvotes: 13

Related Questions