mysql_config not found when installing mysqldb python interface
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The mysql_config not found error occurs when installing mysqlclient (or the older MySQL-python) because the package needs the MySQL C client development headers to compile. The mysql_config binary tells pip where to find these headers and libraries. It is missing because the MySQL development package is not installed on your system. The fix is to install the appropriate -dev or -devel system package for your OS, or switch to a pure-Python MySQL driver like PyMySQL that requires no compilation.
The Error
This happens during the build step because mysqlclient is a C extension that wraps the MySQL C client library (libmysqlclient). The build script calls mysql_config to determine compiler flags, include paths, and library paths.
Fix by OS
Ubuntu / Debian
The default-libmysqlclient-dev package provides mysql_config along with the headers and libraries.
Fedora
CentOS / RHEL
macOS (Homebrew)
If mysql_config is still not found after installing:
macOS (mysql-client only, no server)
Alpine Linux (Docker)
Alternative: Use PyMySQL (No Compilation)
PyMySQL is a pure-Python MySQL driver that does not need mysql_config or any C libraries:
Using PyMySQL as a MySQLdb Drop-In
This is useful for Django and other frameworks that expect MySQLdb.
Alternative: mysql-connector-python
Oracle's official pure-Python driver:
Verifying mysql_config
Docker Setup
Django Configuration
Common Pitfalls
- Installing
mysql-serverinstead of*-dev: The MySQL server package does not include development headers. You specifically needlibmysqlclient-dev(Debian) ormysql-devel(RHEL/Fedora). - MariaDB vs MySQL headers: On many Linux distributions, MariaDB replaces MySQL. The
mariadb-develorlibmariadb-devpackage provides a compatiblemysql_config. Check which is available with your package manager. - Virtual environment PATH:
mysql_configmust be on the system PATH, not in the virtualenv. Ifwhich mysql_configreturns nothing, the dev package is not installed or the path is not set. - macOS Apple Silicon paths: Homebrew installs to
/opt/homebrew/on Apple Silicon instead of/usr/local/. Many guides show the Intel path. Usebrew --prefix mysqlto find the correct location. - Using
MySQL-pythonon Python 3: TheMySQL-pythonpackage (also calledMySQLdb) only supports Python 2. Usemysqlclient(its maintained fork) for Python 3.
Summary
mysql_config not foundmeans the MySQL C client development headers are missing- Install
default-libmysqlclient-dev(Debian/Ubuntu),mysql-devel(Fedora/CentOS), orbrew install mysql(macOS) - For a compilation-free alternative, use
PyMySQLwithpymysql.install_as_MySQLdb()for framework compatibility - In Docker, add the dev package in your Dockerfile before
pip install mysqlclient - Use
which mysql_configto verify the binary is available on your PATH
Related reading
- MySQL connection not working 2002 No such file or directory
- MySQL convert date string to Unix timestamp
- MySQL COUNT DISTINCT
- Mysql count rows using filters on high traffic database
- MySQL incorrect string value error when save unicode string in Django
- Name 'Key' not defined Lambda function to access DynamoDB
- mysql database replication error log. Ways to retrieve it
- MySQL Database won't start in XAMPP Manager-osx

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.