libmysqlclient.so.16 - cannot open shared object file

14 Jul 2009

This is another post under the "simple solutions to annoying problems" category. I was deploying a Rails app to a server on which I'd compiled MySQL from source. The deployment went fine until the deploy:migrate task:

  * executing "cd /path/to/app/releases/20090714141105; rake RAILS_ENV=production  db:migrate"
    servers: ["foo.net"]
    [foo.net] executing command
*** [err :: foo.net] !!! The bundled mysql.rb driver has been removed from 
Rails 2.2. Please install the mysql gem and try again: gem install mysql.
*** [err :: foo.net] rake aborted!
*** [err :: foo.net] libmysqlclient.so.16: cannot open shared object file: 
No such file or directory - /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so
*** [err :: foo.net] 
*** [err :: foo.net] (See full trace by running task with --trace)
 ** [out :: foo.net] (in /path/to/app/releases/20090714141105)
    command finished
failed: "sh -c 'cd /path/to/app/releases/20090714141105; rake RAILS_ENV=production  db:migrate'" on foo.net

The problem was that I'd compiled MySQL with --prefix=/usr/local/mysql and that directory wasn't on the runtime linker path. So I edited /etc/ld.so.conf and added /usr/local/mysql/lib/mysql, ran ldconfig, and voila, all was well.

This problem was a little more confusing since the Rails app itself was running fine, and running script/console worked fine too. But that was because I had added the MySQL lib path to LD_LIBRARY_PATH in /etc/profile. Anyhow, hope this helps someone!