I've reached a point in my Django projects where it made sense to use a MySQL database server instance. This was extremely simple for me on Ubuntu server because I'm pretty familiar with Debian and Ubuntu administration these days. I did have to get my Django code on my local Mac dev environment to talk to MySQL though. Unfortunately this one wasn't as easy as just running a pip (or easy_install) python package installation command. I started getting error messages early on.
Here's something of the step by step on how I got this all to work on my Mac OS X 10.7 Lion OS:
http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/
MySQLdb
* MySQLdb provides the Python bindings to interface with the database.
1. curl -O http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz
2. tar -xvzf MySQL-python-1.2.2.tar.gz
3. cd MySQL-python-1.2.2
* Edit the site.cfg file:
* Uncomment the line that begins #mysql_config =
* Edit the path to point to /usr/local/mysql/bin/mysql_config:
mysql_config = /usr/local/mysql/bin/mysql_config
* Complete the build and installation:
1. python setup.py build
2. sudo python setup.py install
3. cd ..
This isn't working. I get an error message on step 1: (python setup.py build)
ruebenramirez@Ruebens-MacBook-Air:~/Downloads/MySQL-python-1.2.3 $ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.7-intel-2.7/MySQLdb
running build_ext
building '_mysql' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.7-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute llvm-gcc-4.2: No such file or directory
error: command 'llvm-gcc-4.2' failed with exit status 1
I thought that my MAMP install might somehow be causing problems, so I went to the MySQL download site and grabbed the latest MySQL 64 build DMG to install.
* before installation, I made sure to stop the MAMP services and completely shutdown the MAMP management utility
* It turns out that this new MySQL installation doesn't conflict with the MAMP MySQL installation for my purposes because all of my accessing code uses the per installation bound socket file connection mechanism (instead of connecting to the local 3306 port)
http://activeintelligence.org/blog/archive/mysql-python-aka-mysqldb-on-osx-lion/
This helped me get going. It helped me to understand that there were some environment variables that had to be set in order for the software to properly build.
* make sure to place these in your ~/.bash_profile so that you have access to the mysql command even after reboot!
Even after configuring all the environment variables, the MySQL-python package wouldn't run.
The build was still choking on the llvm-gcc-4.2 not found error. Googling the error turned up a couple of things:
* an "easy" way to resolve the missing dependency issue is to install XCode from the App store
* after "installing" from the App store, you still have to open up XCode (in the Applications directory) to complete the install
* this still doesn't install the "command line tools" which was another 180MB download (from the XCode preferences pane's "downloads" section).
Finally after all of this, I have a working local Django install with access to MySQL via a sudo easy_install MySQL-python!
So here's the recap:
- instally the latest MySQL dmg from the mysql.com community site (currently mysql-5.5.22-osx10.6-x86_64.dmg) http://www.mysql.com/downloads/mysql/
- modify your ~/.bash_profile to add these environment variables (add these lines)
-
export PATH=$PATH:/usr/local/mysql-5.5.22-osx10.6-x86_64/bin/
- (or the to whatever your version of MySQL was installed)
-
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
-
export ARCHFLAGS='-arch i386 -arch x86_64'
- install XCode (from the app store and then by running the XCode app found in the /Applications dir) and then also install command line utilities from the preferences "downloads" section
- run: sudo easy_install MySQL-python