Thanks to Timothy Harper for suggesting the (in hindsight fairly obvious) way out of this dilemma: build and link against the 32-bit version of the MySQL library. Unfortunately I didn't find it anywhere near that simple, but here is what I did:
- Install 64-bit MySQL (you're probably already past this)
- Install 32-bit MySQL
- change directory to /usr/local
- re-symlink mysql → to the 64-bit version (since the 32-bit install clobbered the symlink)
- symlink sql32 → to the 32-bit version (for hackery later the name length needs to be the same so when we edit the binary lib file we change as little as possible)
- Re-install 64-bit MySQL (the 32-bit version hosed mine)
- Build the gem against the 32-bit MySQL
- Binary edit your /Library/Ruby/Gems/1.8/gems/mysql2.7/lib/mysql.bundle to fix the broken hard-coded path
You may also need to remove (or move) /Library/Ruby/Site/1.8/universal-darwin9.0/mysql.bundle if Ruby tries to use it over the gem version you installed.
Steps 7 and 8
First, lets build out MySQL gem. If you read the verbose output you'll see it's building and linking against the sql32 libs.
sudo env ARCHFLAGS="-arch i386" gem install -V mysql -- --with-mysql-config=/usr/local/sql32/bin/mysql_config
Unfortunately the mysql.bundle this builds still has a hard reference to /usr/local/mysql/lib (does it get it from the libmysqlclient file which also has it hard coded?) so we will need to open it in a binary editor (I used 0xED) and do a search and replace like this (I just found it manually and re-typed it... I don't actually see a search and replace option):
- local/mysql/lib → local/sql32/lib
0xED doesn't seem to support authenticating sudo style so you may need to save your changes to your desktop and then copy the mysql.bundle back into your gems folder.
Ok, I'll be the first to admit that is a royal pain in the ass. It would have been easier to just re-install 32-bit and be done with it... but I feel a warm, fuzzy sense of satisfaction knowing I'm still using the mighty 64-bit MySQL.
If anyone seems any ideas on how to improve the process please let me know and I'll update the post. I just fired up Rails and confirmed this seems to work perfectly.