Ubuntu, mysql and rails

I just upgraded my work laptop to Ubuntu Natty Narwhal, and then I found all my rails projects broken. Whenever I tried to run up a rails server, I got this:

$ rails server
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach

Exiting
/path/to/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:30:
in `mysql_connection': undefined method `init' for Mysql:Class (NoMethodError)

(followed by a huge stacktrace). Googling didn’t help much, because every time anyone has asked about this on a forum, all of the answers are specific to Macs.

It turns out that the problem is that the mysql gem includes native code, which is built when you install the gem. And my existing mysql gem had been built against mysql libraries that are now, since my upgrade, out of date. So the fix turns out to be maddeningly simple. First, get rid of the gem that doesn’t work:

$ gem uninstall mysql

Next, get hold of the developer API libraries for mysql:

$ sudo apt-get install libmysqlclient16-dev

And finally, download and rebuild the gem again:

$ gem install mysql

Simples. I just hope this quick note saves you the hours of trawling through forums that I had to endure this morning.

Advertisements

One thought on “Ubuntu, mysql and rails

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s