MySQL Support from Python on OS X
It was more work than it should have been, but you can get access to a MySQL database from Python on OS X 10.5 by following the instructions at this blog post.
If you’re using Pydev in Eclipse, be sure /Library/Python/2.5/site-packages is in the System PYTHONPATH. Bring up the Preferences dialog, open Pydev in the tree, click on Interpreter – Python, click New Folder to the right of System PYTHONPATH, and then add the directory, if necessary.
Update 12/27/2009: With MySQL 5.1.41 and Snow Leopard (OS X 10.6), you no longer need to create the lib/mysql directory with symbolic links as described in the above article. Also, since Snow Leopard comes with Python 2.6, the path above for Eclipse should be /Library/Python/2.6/site-packages. I found Geert’s instructions to be quite helpful for Snow Leopard. There’s also a lot of useful info here.
One problem I ran into is that I initially built the MySQL Python connector with a 32-bit version of MySQL 5.1 installed. After upgrading, I forgot to delete the build directory to force the connector to completely rebuild. When I then tried to run “import MySQLdb” in the interpreter, I got the cryptic message “ImportError: dynamic module does not define init function (init_mysql)”. If I had read all of the comments in that last article before figuring this out, I might have gotten a hint from the comment mentioning that not even “setup.py clean” would delete the build directory if you left off the 64-bit architecture flags.












February 22nd, 2008 at 12:25 am
This is not particularly relevant, but I find it interesting. Per the SQLite folks, Mac OS X uses SQLite for Apple Mail and Safari. See: http://www.sqlite.org/famous.html And the new Filemaker, Inc. product (Bento) apparently relies on SQLite.
February 23rd, 2008 at 12:44 pm
SQLite is a very nice embedded database. It’s also used by Google Gears. It seems to be becoming the cross platform embedded database of choice. I’ve used two others that are written in Java that are also very good – HSQLDB (formerly Hypersonic SQL) and Apache Derby (formerly Cloudscape). Derby is packaged with Sun’s Java JDK 6.
December 29th, 2009 at 5:17 pm
[...] just updated an old post on using Python with MySQL on OS X. The good news is that you don’t need to create an extra directory of symbolic links anymore. [...]