OK, if you read two of my other posts on Snow Leopard (here and here) you know I’ve been having a bit of trouble getting MySQL and Python working together. To say the least.
I think I finally did it. And it was probably how I should have started to begin with honestly. Build manually from source.
First download MySQL not from Fink or MacPorts but from Sun itself. OSX MySQL Download. I downloaded the source.
Go into the directory you untarred.
Type the following. (Thanks to Hivelogic for this tip)
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex \ --enable-thread-safe-client --enable-local-infile --enable-shared \ --with-plugins=innobase make sudo make install cd /usr/local/mysql sudo ./bin/mysql_install_db --user=mysql sudo chown -R mysql ./var
Next setup MySQL with launchd. Once again HiveLogic comes to the rescue with a preconfigured plist for launchd. (Or you could just set it up by hand or with Lingon)
Head to your temp directory and do the following. (Any directory will do – just make sure you delete the files afterwards. I have a ~/temp directory for this sort of stuff.)
curl -O http://hivelogic.com/downloads/com.mysql.mysqld.plist sudo mv com.mysql.mysqld.plist /Library/LaunchDaemons sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
MySQL should now run on startup. To start it now (so you don’t need to reboot) do the following:
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
If no errors are reported things are probably working. You can now login to MySQL if you want and poke around to see if everything is working. (I’ll not tutor you there)
Next download the source for MySQL-Python from Python.org.
Modify your path (in ~/.bash_profile) to ensure that /usr/local/mysql/bin is in the path.
Open a terminal in that untarred directory and type the following.
sudo python setup.py install
Le voilà. Everything works. It turned out my error was I’d copied into my Path the location for MySQL I had under Leopard which was /Library/MySQL/bin rather than /usr/local/mysql/bin which is where the above install wants it. Whew.
Hope that helps everyone.
I should note I’ve not yet had time to test everything. If I find any problems I’ll comment here.
Related posts:
- Upgrading to Snow Leopard Part 3: MacPorts
- Upgrading to Snow Leopard Part 1: Python
- Upgrading to Snow Leopard Part 5: The Python Gripes
- Upgrading to Snow Leopard Part 7: One Month Later
- Upgrading to Snow Leopard Part 2: Minor Tips
- Paths and ManPaths in Leopard
- FileMaker to MySQL
- Upgrading to Snow Leopard Part 6: 64bit vs. 32bit
.jpg)
#1 by abhi166 on 2009/09/02 - 3:27 pm
I installed the x86_64 pkg from Sun. Then installed MySQLdb for python with ARCHFLAGS=’-arch x86_64′ python setup.py build/install. (Python2.6)
#2 by Seth Gottlieb on 2009/09/06 - 9:26 pm
Things didn’t go so smooth for me. Even with the -arch x86_64:
>>> import MySQLdb
Traceback (most recent call last):
File “”, line 1, in
File “build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py”, line 19, in
File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 7, in
File “build/bdist.macosx-10.6-universal/egg/_mysql.py”, line 6, in __bootstrap__
ImportError: dynamic module does not define init function (init_mysql)
#3 by Seth Gottlieb on 2009/09/23 - 7:47 am
I learned that there are two solutions to this problem. The one I discovered first is to use the 32 bit versions of both python and MySQL: http://www.zen-hacking.com/2009/09/01/python-mysql-under-snow-leopard/
Then I learned about a better solution: http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/?cp=all
Apparently the issue is that the “clean” option doesn’t really clear out prior builds of the software. It is fixed by manually deleting the former build.
#4 by Michael Kumm on 2009/10/18 - 4:28 pm
Thanks – this has been on my todo list for a while – thanks for posting – it worked!
#5 by Nivas R on 2009/12/25 - 11:49 am
Thanks for the article, it worked.
Initially i was having problems with the compile – because I had spaces in the folder where I had downloaded the source (the folder was “My Sql Src”).
If someone there is facing issues with the make, it could be spaces in the directory…
#6 by Rom on 2010/03/18 - 9:38 am
Just to let you know that you say “Et voilà” and not “Le voilà”!
Cheers
#7 by Clark on 2010/03/29 - 10:47 pm
Yeah, well I won’t tell you how well I did in French back home in Canada… I was the kid in honors physics, biology and math and remedial French.
#8 by Danilo on 2010/04/03 - 4:32 pm
can someone help me? when i unttar the file, it doesn’t create or anything like so I can run configure and make command… I always get this:
Danilo:src danilo$ cd mysql-5.1.45-osx10.6-x86/
Danilo:mysql-5.1.45-osx10.6-x86 danilo$ ./configure –prefix=/usr/local/mysql –with-extra-charsets=complex \
> –enable-thread-safe-client –enable-local-infile –enable-shared \
> –with-plugins=innobase
-bash: ./configure: No such file or directory
#9 by Clark on 2010/04/03 - 9:50 pm
I’d strongly suggest using MacPorts instead of downloading a file.
#10 by Danilo on 2010/04/03 - 10:07 pm
I got it working… I was messing with the architecture since I upgraded my python to the latest 2.6.5 version which is 32bit and I didn’t know it.
So I simple downloaded mysql pkg 32bit for snow leopard and for the mysqldb i used:
ARCHFLAGS=”-arch i386″ python setup.py build
sudo ARCHFLAGS=”-arch i386″ python setup.py install
So happy! :D