16

I just upgraded ubuntu from 11.10 to 12.04 and after that when I run my server inside my rails project I got this error

$ rails s
/usr/share/ruby-rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': 
libmysqlclient_r.so.16: cannot open shared object file: No such file or directory - 
/usr/share/ruby-rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/lib/mysql2/mysql2.so (LoadError)

any help please?

Azzurrio
  • 1,330
  • 1
  • 17
  • 35

4 Answers4

25

Go to your project and follow the steps,

rvm gemset empty <gemset name>
gem install bundler
bundle install

It will solve your problem.

If that does not work, or if you are not using rvm, please use

gem uninstall mysql2
bundle install

from one of your mysql2-using Rails project's directory.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
Santosh
  • 1,251
  • 9
  • 15
  • what do you mean with ?? – Azzurrio Apr 29 '12 at 05:41
  • 1
    Your project's gemset name. Go to your project and hit 'rvm current' and whatever after **@** letter that is your current gemset name. – Santosh Apr 29 '12 at 05:47
  • I haven't any gemset in my rvm, when I type "$ rvm current" I got >> ruby-1.9.3-p125 – Azzurrio Apr 29 '12 at 05:56
  • 5
    Okay, then remove mysql2 gem and install it again. 'gem uninstall mysql2' then 'bundle install' – Santosh Apr 29 '12 at 06:09
  • I was following your instructions and found out that if you empty out your gemset, then you are uninstalling bundler and you'll need to reinstall it. I added `gem install bundler` to your answer. – David Grayson Sep 21 '12 at 22:24
1

Well, I would suggest double checking the ruby and the rails version and make sure they are the same ones u created your project with. Maybe you have to change the version using rvm:

  • rvm use 'Version'

Maybe you can uninstall and reinstall the mysql packages again, also try installing:

  • sudo apt-get install mysql-client mysql-server libmysqlclient16-dev

or

  • sudo apt-get install mysql-client mysql-server libmysqlclient-dev

Also try uninstalling and reinstalling your mysql gem. This blog post had a solution for this error as well, although the error was cause at a different time.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
  • ruby & rails versions are OK, the other 2 commands are the same, and when i try to install "libmysqlclient16-dev" I got this error >> confilcts with the installed package 'libmysqlclient-dev' – Azzurrio Apr 29 '12 at 06:11
  • In my opinion you have to reinstall a couple of these packages, even the gemfile. It might be a compatibility issue between the mysql gem you are using and the drivers you have installed for mysql. Was the link referring to the exact same problem you were having? – Babak Basseri Apr 29 '12 at 08:23
1

I followed Babak's instruction that he posted and it worked after a small change.

My system is Ubuntu 12.04 server and it has Ruby1.9.3 installed so I did this

sudo apt-get install mysql-server libmysqlclient-dev

Seems like the libmysqlclient16-dev is now renamed to libmysqlclient-dev in Ubuntu 12.04

Afterwards I ran

gem install mysql2
Community
  • 1
  • 1
mackrauss
  • 96
  • 1
  • 3
0

For me nothing up there work. Then I found this and try to delete and create again the database.yml file. AND IT WORKS!

Community
  • 1
  • 1
Foton
  • 1,197
  • 13
  • 24