Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

airflow mysql_hook No module named 'MySQLdb'

Tags:

python

airflow

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!

like image 917
Steve.Gao Avatar asked Mar 02 '23 20:03

Steve.Gao


1 Answers

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.

like image 162
Elad Kalif Avatar answered Mar 16 '23 10:03

Elad Kalif