Skip to main content

Install MySQL for python on Mac OS 10.9 with XAMPP



Assume that you already have Python installed.
1. Install XAMPP for MAC

http://sourceforge.net/projects/xampp/files/
As it is a dmg file, it should be easy to be installed.

2. Now you need to install MySQLdb package for Python
a. Download the lastest module of MySQLdb here :
http://sourceforge.net/projects/mysql-python/files/latest/download

b. Extract it to your prefered location.
Notice: You might need to change site.cfg according to your mysql_config path. See the next step

c. Setup your path
Because you need to setup /bin and /lib folder of XAMPP's MySQL. So, let prepare your $PATH variable.
> Edit your ~/.bash_profile ( or ~/.profile) by adding the following lines: 

export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib
export PATH=/Applications/XAMPP/xamppfiles/bin/:$PATH

Notice: if you are not using XAMPP, you should edit above PATH by your mysql equivalent path.
for example /usr/local/mysql/lib and /usr/local/mysql/bin
Notice: About site.cfg(in your extracted package), edit it:

mysql_config=/Applications/XAMPP/xamppfiles/bin/mysql_config

d. Ready to build and install 
Open the mysql-python folder you've extracted.
Commands:

sudo python setup.py build
sudo python setup.py install

Some errors my occured in OSX 10.9 :
clang: error: unknown argument: '-mno-fused-madd'
You could fix this error by replacing above commands by:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py build

sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py install

e. Test your result
Commands: 
python
>>> import MySQLdb
>>> MySQLdb.apilevel

If you find no error, congratulations.

3. Some utilities

a. MySQL XAMPP
change your PATH variable so you can use mysql in command line. Like the following:

export PATH = /Applications/XAMPP/xamppfiles/bin/mysql/:$PATH

Test: 
mysql -u root -p 
Default password of XAMPP MySQL is empty

b. loading library error
You might catch the following error when you try using python mysql:


ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so

  Reason: image not found

This is because the mysqllibrary (of XAMPP) could not be found. You should make a link of mysql libray file to your /usr/lib :


sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib


Comments

  1. MAC OSX 10.10
    I have some problem
    which occur error

    clang: error: unknown argument: '-fabi-version=2'
    error: command 'cc' failed with exit status 1

    pls, suggest me ^_^

    ReplyDelete

Post a Comment

Popular posts from this blog

Install Ruby on Rails on MAC

Hello, I am quite familliar with Apache's friend products like XAMPP, LAMPP... And this is the first time I try Ruby on Rails(RoR). I'm quite stuck on installing it. As a normal PHP guy, I first try install Rails, following this tutorial: http://installrails.com/ And the next thing I want to learn about is how RoR works with MySQL, PhpMyadmin. So I tried to make it connect to XAMPP's MySQL but it did not work at all. I found out that, using mySQL in XAMPP package is not a common method, what I should do is to install MySQL as a single service onto my MAC. So I did following: 1. Install MYSQL with HomeBrew Did you install HomeBrew, if not, please follow:  https://coolestguidesontheplanet.com/installing-homebrew-on-os-x-el-capitan-10-11-package-manager-for-unix-apps/ Next, type this command to install MySQL to your machine: $ brew install mysql This will install mysql to your computer, if the installation is success, you could try start using mySQL with this c...

Server-side HTML vs. JS Widgets vs. Single-Page Web Apps

When I was deciding which architecture could fit our start up service, I found that API-centric architecture is very efficient. However, it has disadvantages as well, so, finally I can find what should I depend on to choose. Here is the content of pamela fox's blog  At the recent  GOTO Chicago conference , I gave a talk on  "Frontend Architectures: from the prehistoric to the Post-modern."  In just my first 10 months at Coursera, I've experienced the joys and woes of many different frontend architectures, and I wanted to share what I learnt. I detail everything in  the slides , but I'll summarize my thoughts here as well. How do you pick an architecture? We could make our decision by just checking Twitter and seeing what all the cool kids are talking about, but uh, let's pretend that we're more scientific about it than that, and figure out whats important to us as web developers. To start off with, here are a few things that users care a ...