1

When I run rake db:create I get following error

xyz-MacBook-Pro:ruby_project xyz$ rake db:create
rake aborted!
dlopen(/Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle

I have mysql 5.1.66 installed in my system and my database.yml file structure is

adapter: mysql2
encoding: utf8
reconnect: false
database: ruby_test
pool: 5
username: root
password:
host: /tmp/mysql.sock

Below are contents of mysql folder in my system

libdbug.a           libmysqlclient_r.a
libheap.a           libmysqlclient_r.dylib
libmygcc.a          libmysqlclient_r.la
libmyisam.a         libmysqld.a
libmyisammrg.a          libmystrings.a
libmysqlclient.16.dylib libmysys.a
libmysqlclient.a        libvio.a
libmysqlclient.dylib    libz.a
libmysqlclient.la       libz.la
libmysqlclient_r.16.dylib   plugin

Can someone help me with this issue?

user1247412
  • 647
  • 7
  • 16
  • 29
  • The same issue has been satisfactorily answered at http://stackoverflow.com/questions/10557507/rails-mysql-on-osx-library-not-loaded-libmysqlclient-18-dylib – Prakash Murthy Oct 23 '12 at 07:06
  • It has libymysqlclient18.dylib which it was not able to find. In my case, I don't have libmysql18.dylib file. – user1247412 Oct 23 '12 at 07:13

3 Answers3

4

Install the gem for mysql2 using the command
gem install mysql2
check the bundle to make sure it used mysql as default database. And put the libmysql.dll file in your MySQL bin folder.

ѕтƒ
  • 3,547
  • 10
  • 47
  • 78
1

One of the simple and best way is to create a soft link by command -

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

http://rorguide.blogspot.com/2011/07/getting-error-library-not-loaded.html

Dipak Panchal
  • 5,996
  • 4
  • 32
  • 68
1

You can install libmysqlclient. I guess you are using Ubuntu, then using following to install

sudo apt-get install libmysql-ruby libmysqlclient-dev
Shamith c
  • 3,719
  • 3
  • 25
  • 33