Skip to content

Instantly share code, notes, and snippets.

@ShirishRam
Last active October 19, 2023 19:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShirishRam/99fc3def9d35e75e96a562f0524b0d46 to your computer and use it in GitHub Desktop.
Save ShirishRam/99fc3def9d35e75e96a562f0524b0d46 to your computer and use it in GitHub Desktop.
Installing MySQL, MySQL connector, MySQL Python client on Mac OS HighSierra

Installing MySQL Python client on Mac using Homebrew and pip

Verify if MySQL server is installed:

$ brew info mysql Expected output: mysql: stable 8.0.12 (bottled)

If you don't have MySQL installed, then run below command:

$ brew install mysql

If you don't have brew installed, then run below command:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Temporarily remove symlink created during the MySQL install step:

$ brew unlink mysql

Now install MySQL connector:

$ brew install mysql-connector-c

Locate MySQL config file:

$ which mysql_config

Edit the mysql_config file, under # Create options:

Replace: libs="$libs -l "

By: libs="$libs -lmysqlclient -lssl -lcrypto"

Install Python MySQL client:

$ pip install mysqlclient (use sudo if required)

Alternatively, you can install this: $ pip install MySQL-python (use sudo if required)

Remove symlink:

$ brew unlink mysql-connector-c

Symlink MySQL service:

$ brew link mysql

@ardevpk
Copy link

ardevpk commented May 9, 2023

ld: library not found for -lmysqlclient

@ardevpk
Copy link

ardevpk commented May 9, 2023

error: command '/usr/bin/clang' failed with exit code 1

@vitalis
Copy link

vitalis commented Oct 19, 2023

For me there was no need to change the mysql_config file/

But only the following command worked:

MYSQLCLIENT_CFLAGS="-I$(brew --prefix)/opt/mysql-client/include/mysql" MYSQLCLIENT_LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment