Recovering MySQL and MySQLdb (python module) after upgrading to Snow Leopard

July 5th, 2010 § 0

Ahh, that’s a nice and descriptive title.

Needless to say, I had the darnest time doing this. Upgrading mysql was not too big of an issue, but getting MySQLdb to work was a whole other game.

Anyway, here are the steps I took.
The instructions for upgrading MySQL came from entropy.ch and are as follows:

  1. Save your current database data before doing anything: cd /usr/local/mysql; sudo tar -cvf /tmp/mysql-data.tar data
  2. Then download the MySQL installer from the MySQL website. At first I chose to download “Mac OS X ver. 10.6 (x86, 32-bit), DMG” which, I believe, caused all my problems with MySQLdb. So download Mac OS X ver. 10.6 (x86, 64-bit), DMG unless you know you have a 32 bit machine.
  3. Once downloaded, unpack and install the MySQL package and even the prefPane to make your life easier.
  4. To restore your old data, run this command: cd /usr/local/mysql; sudo tar -xf /tmp/mysql-data.tar
  5. I’m not sure if this is needed, in the attempt that worked, I followed the instructions to the dot so I did reboot my computer (although the MySQL install didn’t require me to).
  6. Start MySQL either through the System Preferences (if you installed the prefPane above) or by running: sudo /usr/local/mysql/bin/mysqld_safe

That’s all there was to installing MySQL. Note that in my system I didn’t have to change the ownership of the database data when it was “imported” into the new install. If you have to do that (i.e. can’t login with the usual username/password combo) see the instructions in the link I posted above.

Now onto MySQLdb. These instructions are taken from Geert JM Vanderkelen.

  1. Download MySQL-python-1.2.3c1.tar.gz from the Python Package Index.
  2. Untar it and ensure “/usr/local/mysql/bin” is in your PATH, if not see the above link on how to add it.
  3. Run this command: ARCHFLAGS="-arch x86_64" /usr/bin/python setup.py build (Ensure you don’t have a 64 bit machine before changing it.)
  4. And finally, install it with the following command: sudo /usr/bin/python setup.py install

Once all that is done. You can test it like this:

$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

If that gives you no errors, you’re set. Now get back to doing actual work :) .

  • Share/Bookmark

MySQLdb-python on OS X (10.5)

November 13th, 2008 § 0

In an effort to setup Django for a project I’m working on (more on that another day), I ran into some issue installing MySQL-python (version 1.2.2). Googling around I found a few discussions regarding it. After fiddling around with it for a while, I managed to get it going.

Here’s how:

(Assuming you have MySQL installed and have the /usr/local/mysql/bin in your path.)
Comment out the following three lines in <MySQL-python location>/_mysql.c, as such:

/*
#ifndef uint
#define uint unsigned int
#endif
*/

Now, run the build and install commands:

python setup.py build
sudo python setup.py install

We can do a quick test:

python
Python 2.5.1 (r251:54863, Jul 23 2008, 11:00:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
/Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg/_mysql.pyc, but /Applications/MySQL-python-1.2.2 is being added to sys.path
import sys, pkg_resources, imp
>>> conn = MySQLdb.connect(host = “HOST”, user = “USER”, passwd = “PASS”, db = “DATABASE”)
>>> cursor = conn.cursor()
>>> cursor.execute(“SELECT VERSION()”)
1L
>>> row = cursor.fetchone()
>>> row[0]
’5.0.67′
>>> cursor.close()
>>> conn.close()

Now sure if that warning will have implications later; doesn’t seem like it but you never know.

  • Share/Bookmark

Where Am I?

You are currently browsing entries tagged with mysql at life of a gizmo.