Install MySQL and MySQLClient(Python) in MacOSApr 19, 2019 · 2 min read · 18 comments
Connecting to MySQL from Python in MacOS is a very problematic and painful process. In this post, we are going to see how to install MySQL and connect a Python application to it using mysqlclient.
Table of contents
Step one: install Homebrew ︎
You need to install Homebrew in you local machine. You can do it by:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step two: install MySQL ︎
Using Homebrew you can install mysql simply by:
brew install mysql
Then setup the credentials in MySQL server using the following command:
Finally if you want to start at login and as a background service, run this:
brew services start mysql
Step three: install MySQL-Connector-C ︎
For connecting any other application to MySQL, you need to install a connector. You can do it like this:
brew install mysql-connector-c
Then according to mysqlclient’s documentation, you need to put a bugfix at
mysql_config. For that first type
mysql_config in terminal.:
>> mysql_config Usage: /usr/local/bin/mysql_config [OPTIONS] Compiler: ...
It will show where you need to find
mysql_config. Then you can use any of the editor of your liking and change the following lines inside the
# on macOS, on or about line 112: # Create options libs="-L$pkglibdir" libs="$libs -l "
# Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto"
Step four: install XCode-Select ︎
You can do this by:
Step five: install OpenSSL ︎
Please run the following command:
brew install openssl
Then add its path to environment using following line:
Step six: unlink MySQL and link MySQL-Connector-C ︎
You need to unlink mysql and link mysql-connector-c:
brew unlink mysql brew link --overwrite mysql-connector-c
Step seven: install mysqlclient ︎
You should be able to use
pip install mysqlclient without any errors.
Step eight: link MySQL back again ︎
Now, you need to do the opposite of Step six:
brew unlink mysql-connector-c brew link --overwrite mysql
mysqlclient should work fine and will have no problem connecting your application from mysql to python.
In conclusion ︎
In this article, we have seen installing MySQL from Homebrew. I never used MySQL installed from Oracle website, so don’t know how to fix it. Better if you uninstall that and install MySQL from scratch using Homebrew.
Lets say you have been using a class named ClassA, objects created from that class has been used in many places. Now you …
When you are using OpenShift, you will be using routes to expose a route from a service. Let’s say you want to …