Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Installing the Airflow MySQL provider fails on pkg-config or mysqlclient

Errorpip install apache-airflow-providers-mysql stops with a pkg-config error

Short answer

The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library. The build asks pkg-config for the compiler flags. If pkg-config or the development package is missing, the build stops. Install pkg-config, build tools and the client development package, then rerun pip.

  • Applies to Ubuntu 24.04, Python 3.12, apache-airflow-providers-mysql
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Scroll up in the pip output to the first error line from the mysqlclient build, then check that pkg-config exists and knows the MySQL client.

    which pkg-config
    pkg-config --cflags --libs mysqlclient
  2. 2Match what you see, then jump to its fix

    1. 1which pkg-config prints nothing, or the build fails when it asks for mysqlclient flagspkg-config, a compiler or the client headers are not installedFix
    2. 2The packages above are installed and the build still cannot find the librarypkg-config is installed but does not return flags for mysqlclientFix

What does the error look like?

  • pip install apache-airflow-providers-mysql stops with a pkg-config error
  • Building the mysqlclient wheel fails during the install

Cause 1 of 2

pkg-config, a compiler or the client headers are not installed

1Check

The provider lists mysqlclient as a requirement, and mysqlclient gets its flags by running pkg-config for the mysqlclient library. Without pkg-config, a compiler and the client development files, there is nothing to build against.

which pkg-config gcc
dpkg -s default-libmysqlclient-dev

2Fix

Install the packages the mysqlclient project lists for Debian and Ubuntu, then install the provider again.

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config
pip install apache-airflow-providers-mysql

3Verify

pkg-config now answers, and the provider imports.

pkg-config --cflags --libs mysqlclient
python -c "import MySQLdb; print('ok')"

Confirmed by github.com

Did this fix it?

Cause 2 of 2

pkg-config is installed but does not return flags for mysqlclient

1Check

mysqlclient reads its flags from pkg-config by default, but it also accepts them from two environment variables. If pkg-config cannot report them for your client library, you can pass the flags yourself.

pkg-config mysqlclient --cflags --libs

2Fix

Set MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS from whatever pkg-config reports for your client library (or write the paths by hand), then install again in the same shell.

export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags`
export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`
pip install mysqlclient

3Verify

The wheel builds, and the provider installs.

pip install apache-airflow-providers-mysql
python -c "import MySQLdb; print('ok')"

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Install the system packages before pip install on every new server or image, and keep them in your Dockerfile or provisioning script.
  • Pin the provider version in your requirements file so a rebuild installs the same mysqlclient requirement.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.