Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby mysql2 gem compiled for wrong mysql client library version

After updating MySQL to 5.5 using apt-get, the mysql2 gem stopped working.

Here's the error:

Incorrect MySQL client library version!
This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)

I tried reinstalling with mysql_config but it doesn't seem to make a difference..

gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config

Correspondingly, I tried telling bundle to compile mysql2 with mysql-config but still, the error remains..

bundle config build.mysql2 --with-mysql-config=/usr/bin/mysql_config
bundle install

When I tried an older version of the gem (v0.2.6) the rails console opens but crashes once I run any type of query.


Here's the full error stack when trying the most current version of the mysql2 gem:

[marco@linode:/www] 07:29:00 AM: rails c
/users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `require': Incorrect MySQL client library version! This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `<top (required)>'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
  from /www/config/application.rb:7:in `<top (required)>'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `require'
  from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

Edit: I removed all mysql2 gemspecs from cache, uninstalled all mysql-related packages via apt-get and reinstalled everything afresh, then tried again to install the gem with the mysql-config flag .. but it all proved futile. The error remains.

Edit 2: As suggested by John Bachir, I confirmed that mysql_config contains MySQL version 5.5.

like image 562
Marco Avatar asked Nov 15 '11 19:11

Marco


4 Answers

On Mac using Brew verify the versions installed on your machine:

ls /usr/local/Cellar/mysql*

Them remove the wrong version such as:

brew uninstall mysql-client

Remove the gem:

gem uninstall mysql2

Run bundle again:

bundle install
like image 97
monteirobrena Avatar answered Oct 14 '22 22:10

monteirobrena


Late to the party, but I just did

gem uninstall mysql2
gem install mysql2

Gem path was

$ bundle show mysql2
/var/lib/gems/1.9.1/gems/mysql2-0.3.16
like image 12
François Drolet Avatar answered Nov 04 '22 16:11

François Drolet


I have encounter the same error when using Ubuntu Server 11.04 and Percona Server, what have I done was:

replace /usr/lib/libmysqlclient.so.16.0.0 with /usr/lib/libmysqlclient.so.18.0.0

like image 8
ShiningRay Avatar answered Nov 04 '22 16:11

ShiningRay


I had this problem and just needed to recompile the gem. I don't know if there's a more programmatic way with bundler, but I just removed the compiled gem and then re-ran bundler:

$ bundle show mysql2
/usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ rm -rf /usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ bundle
like image 7
seb Avatar answered Nov 04 '22 16:11

seb