Dualistic

Pol Llovet :: Life & Work

plum blossoms

Ruby Dbi and Mysql Driver

« »

If you want to do direct access to mysql (or other databse) you can use the dbi gem to do it. But what the docs don’t tell you is that you need to gem install a database driver also.

So if you want to use mysql, you do:

1
$ sudo gem install dbi dbd-mysql

There are other dbd’s for different databases.

Also: If you are getting this error:

1
2
3
4
5
6
7
LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  from /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in `require'
  from (irb):1
  from /Library/Ruby/Gems/1.8/specifications/actionpack-1.13.6.gemspec:13

Then you need to do this:

1
sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.15.dylib /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle

The last argument may need to be modified to match the “Referenced from” line from your error.

Test the fix by opening up irb and doing a require ‘mysql’

Comments