Monday, June 25, 2007

Getting MySql Working Again with Rails

Over the last few days, and for no reason that I could identify, Rails started throwing numerous connection errors (on Mac OS X). This was quite frustrating, since I could not identify anything that had changed. Nevertheless, I opted to try to upgrade the Mysql driver to see if that would do the trick ( it had in the past).

The first thing I did was upgrade Mysql to 5.0.41 from 5.0.14 or so. Easy peasy. Next, I upgraded the sql driver -

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

So far so good. So I kick off mongrel.....and BAM - get a string of errors, including 

dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

After much googling, and not a little telling the ether what I thought of the whole matter, I found a solution:

sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
/usr/local/mysql/lib/libmysqlclient.15.dylib /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle


After this, no problems - and most importantly, the intermittent connection errors have stopped.