Mac OS X
mysql_config
EnvironmentError
troubleshooting
installation issues

Mac OS X - EnvironmentError mysql_config not found

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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:

bash
mysql_config --cflags
mysql_config --libs

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.

bash
brew install mysql-client

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:

bash
export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"

On Intel Macs:

bash
export PATH="/usr/local/opt/mysql-client/bin:$PATH"

After that, confirm the tool is visible:

bash
which mysql_config
mysql_config --version

Once those commands work, retry the package install.

Reinstall the Python Package

After fixing PATH, reinstall the package:

bash
pip install mysqlclient

If you use a virtual environment, activate it first so the package lands in the correct interpreter environment.

This sequence is usually enough:

  1. install MySQL client tools
  2. make mysql_config visible in the shell
  3. 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:

bash
export MYSQLCLIENT_CFLAGS="-I/opt/homebrew/opt/mysql-client/include/mysql"
export MYSQLCLIENT_LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib -lmysqlclient"
pip install mysqlclient

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:

bash
python -c "import platform; print(platform.machine())"
which python
which pip

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_config is used by build tools to discover MySQL client compiler and linker settings.'
  • On macOS, installing mysql-client with Homebrew usually provides it.
  • Add the Homebrew client bin directory to PATH so pip can find mysql_config.
  • Retry the Python package installation after confirming which mysql_config works.
  • Watch for outdated Python packages and architecture mismatches on modern Macs.

Course illustration
Course illustration

All Rights Reserved.