Ruby mysql2 gem compiled for wrong mysql client li

2019-01-23 16:45发布

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.

13条回答
爷的心禁止访问
2楼-- · 2019-01-23 17:05

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
查看更多
冷血范
3楼-- · 2019-01-23 17:07

Other than making sure that only the libmysqlclient18 library was installed (and not 16), what made it work for me was installing libmysqlclient18-dev (the dev headers).

This is with Percona Server 5.5 on Ubuntu Precise.

查看更多
狗以群分
4楼-- · 2019-01-23 17:07

if you know c program,you can remove this message. omit it.

  1. open this mysql.gem mysql-2.9.1.gem\data.tar.gz\data.tar\ext\mysql_api\mysql.c

  2. find "This gem was compiled for" ,delete this if sentence .

    if (lib[i] != MYSQL_SERVER_VERSION[i]) { Line 1897: rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib); }
    

you need set sys-variable for local gemfile install on windows system . SET HOMEDRIVE=c: ERROR: While executing gem ... (Errno::EINVAL) Invalid argument @ rb_file_s_stat - U:/

install local gem file . C:\Rails>gem install --local mysql-2.9.1.gem --install-dir=c:/tmp --platform= ruby -- --with-mysql-dir=C:/Rails/mysql-connector-c mysql-connector-c visit mysql http://dev.mysql.com/downloads/connector/c/ . you don't care version.

try again. require 'mysql'

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-01-23 17:10

I meet this problem again and I could not solve it with my previous method(use an older version mysql2 gem). So I try another method as these step:

1.find which mysql_config that your gem library depend on.

mysql_config situation is different in different people's machine, and one people machine can have several mysql_config, so there is no standard mysql_config path for everyone. As this question for example, the mysql_config version is "5.1.58", so you can search "mysql" file in root to find which has related with "5.1.58":

cd /

sudo find -name "mysql" ./

2.install mysql2 gem library again with specific mysql_config path find in step 1

gem install mysql2 -- --with-mysql-config=<%your_specific_mysql_config_path%>
查看更多
在下西门庆
6楼-- · 2019-01-23 17:12

Make sure that /usr/bin/mysql_config is indeed the one that came with 5.5.

查看更多
三岁会撩人
7楼-- · 2019-01-23 17:14

I came across a similar problem:

Incorrect MySQL client library version! This gem was compiled for 5.6.12 but the client library is 5.5.28.

And my MySQL version on Mac:

$ mysql --version
mysql  Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using  EditLine wrapper

and the mysql2 gem installed by bundle install is mysql2-0.3.13

I solved this problem by just setting the mysql2 gem to an older version in the Gemfile:

gem 'mysql2', '0.2.6'

If '0.2.6' does not work for you, you could try another old version number.

查看更多
登录 后发表回答