Mac OS X - EnvironmentError mysql_config not found
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The error EnvironmentError: mysql_config not found usually appears on macOS when you try to install a Python package such as mysqlclient that needs MySQL client headers and libraries at build time. The package installer looks for mysql_config to discover include paths, linker flags, and client-library information. If that executable is missing or not on your PATH, the build fails even if Python and pip are otherwise fine.
What mysql_config Is For
mysql_config is a helper binary shipped with MySQL or compatible client development packages. Build tools call it to answer questions such as:
- where the MySQL header files live
- which client library to link against
- which compiler flags are needed
You can see what it returns by running:
If the shell says the command does not exist, the Python package build will usually fail for the same reason.
Install a MySQL Client Package on macOS
On modern macOS, the usual fix is to install a MySQL client package with Homebrew.
Homebrew often keeps that package in a non-default prefix, so you may need to add it to your shell PATH.
On Apple Silicon Macs:
On Intel Macs:
After that, confirm the tool is visible:
Once those commands work, retry the package install.
Reinstall the Python Package
After fixing PATH, reinstall the package:
If you use a virtual environment, activate it first so the package lands in the correct interpreter environment.
This sequence is usually enough:
- install MySQL client tools
- make
mysql_configvisible in the shell - rerun
pip install
When the Package Is Old
Some older guides still refer to MySQL-python, which is legacy Python 2-era software. On current Python versions, mysqlclient is the usual package people mean.
So if you are following an older tutorial and see this error, check whether the package itself should be updated as well as the system dependencies.
An Alternative: Explicit Build Flags
In some environments, especially with newer packaging flows, you may be able to provide compiler and linker flags explicitly instead of relying on mysql_config.
Example:
This is more manual and usually less convenient than having mysql_config available, but it can help when the build toolchain is unusually strict or customized.
Check Your Python and Architecture
On macOS, build errors can also come from architecture mismatches. For example, an Apple Silicon Python environment combined with Intel-only libraries can create confusing compile or link failures.
Useful checks:
If the interpreter, package manager, and MySQL client tools come from inconsistent environments, fix that before retrying the install.
Common Pitfalls
The most common mistake is installing MySQL but not exporting the directory that contains mysql_config into the shell PATH.
Another issue is using an outdated package such as MySQL-python on a modern Python version and then debugging the wrong problem.
Some users also edit .zshrc or .bash_profile but forget to reload the shell, so pip still runs without the updated PATH.
Finally, remember that a package build running inside a virtual environment still depends on system-level client libraries. The venv isolates Python packages, not MySQL headers installed by Homebrew.
Summary
- '
mysql_configis used by build tools to discover MySQL client compiler and linker settings.' - On macOS, installing
mysql-clientwith Homebrew usually provides it. - Add the Homebrew client
bindirectory toPATHsopipcan findmysql_config. - Retry the Python package installation after confirming
which mysql_configworks. - Watch for outdated Python packages and architecture mismatches on modern Macs.
Related reading
- Machine Learning on PostgreSQL
- MacOSX homebrew mysql root password
- make an ID in a mysql table auto_increment after the fact
- Make Hibernate ignore instance variables that are not mapped
- MacOS Catalina(v 10.15.3) Error “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser
- macOS on VMware doesn't recognize iOS device
- Making backup from database to another server
- Manage conflicts and lag on Postgres Replication in Hot Standby with read heavy Slave

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.