First, are you sure you want to use MySQL-python? This is a mostly-dead project that's been semi-maintained for legacy support for the past half decade, and doesn't even work with current versions of MySQL. It wants 5.0 or maybe 5.1; the current version is 8.0, and even the current legacy version is 5.7.
Other options include:
mysql-connector
, aka MySQLConnector/Python: This is the officially supported library, from MySQL/Oracle. It can be a bit slow, which doesn't matter for most projects, but it can sometimes. It also has a different API (although if you stick to DB-API 2 methods, the only difference is the connect call; beyond that it should just be low-level stuff that's different).
mysqlclient
: This is the package that Django and some other frameworks use. It's an updated fork of MySQL-Python
(with a few things from its abandoned successor, moist
). It can even be configured to install itself as MySQLdb
, the same name used by MySQL-python
.
PyMySQL
: A third-party package built to be as compatible as possible with the old MySQL-python
but simpler and easier to maintain, and install.
cmysql
, a fork of PyMySQL
that's only slightly harder to install, but should be faster than it, or than mysql-connector
.
Some linux distros—including, IIRC, recent versions of Ubuntu—provide a package named python-MySQLdb
or similar that is not actually MySQL-python, but instead mysqlclient
built with the install-as-MySQLdb option. So, if the only reason that you're trying to use MySQL-python
is that it's what you were using on some Ubuntu box, it's probably not what you were using, and therefore not what you want.
Some of these alternative also require MySQL (specifically, MySQLConnector/C
, aka libmysqlclient
, and its development libraries), some don't—but they're all compatible with current versions. (Although there are some notes on 8.0 crypto changes in the docs for PyMySQL and cmysql, which you might want to read if you use 8.0.)
Anyway, if you really want MySQL-python, then you will need to install MySQL in a 5.x version. The INSTALL
points you to MySQL downloads.
If you want 5.0 or 5.1, you will have to dig through the Downloads
folder at one of the mirrors to find a source package and follow the instructions to build and install it, since there are no binary installers that work on current Macs.
If you want later 5.x versions—which, remember, are not supported by MySQL-python, but they might work—Oracle is still providing Mac binary installers for those. If you can't find them in the main downloads section, the mirrors' Downloads folder will have them. As of right now, 5.6 and 5.7 have binary installer packages that end with -macos10.13-x86_64.dmg
.
However, you might be happier installing it with Homebrew. Follow the instructions on that page to install brew
, then to use it to:
brew install mysql@5.5
MySQL-python also requires OpenSSL libraries, and Apple deliberately hides the ones used by the OS to prevent people from accidentally building code against an old version and not getting security updates. The newer libraries should all know how to handle this, but MySQL-python does not. The easiest way to install a usable OpenSSL is with Homebrew again:
brew install openssl
But don't just run that command and close the window. Read the output, because you have to do all the stuff it says if you want MySQL-python to build.