Ruby mysql2 gem compiled for wrong mysql client library version

元气小坏坏 提交于 2019-11-29 01:50:24

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

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

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
Xiao Li

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.

Rather than moving library files, you might also check the package list for your system -- if you upgraded to 5.5 using apt-get, it's likely that you still have 5.1 libraries lying around that you don't need anymore at all. For example, on a system where we encountered a similar issue, we still had the 5.1 library:

$ sudo dpkg -l | grep mysql
ii  libmysqlclient-dev               5.5.13-rel20.4-136.lucid                 Percona Server database development files
ii  libmysqlclient16                 5.1.61-rel13.2-431.lucid                 Percona Server database client library
ii  libmysqlclient18                 5.5.13-rel20.4-136.lucid                 Percona Server database client library

Rather than copying the 5.5 library over the 5.1 library, you should be able to remove it:

$ sudo apt-get remove libmysqlclient16

For us, this has been more reliable than the library renaming solution proposed earlier.

Xiao Li

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%>

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.

I tried all the answers above and my final approach was fairly simple -- delete the entire bundled gem stack and reinstall everything. That finally got around the mysql client issue. i.e.

rm -rf /Users/sjohnson/.rvm/gems/ruby-1.9.3-p484@adp_rails3
bundle install

Gao.YD

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'

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

In my case, I had various files from libmysqlclient15 (dated 2009) and libmysqlclient16 (dated 20012) left in /usr/lib, possibly from a botched Ubuntu upgrade.

Removing the libmysqlclient15 files (which were linked to libmysqlclient15.so) solved my problem.

On my machine I had to uninstall the gem, then re-direct the symlink /usr/local/mysql to the correct Homebrew version:

ln -s /usr/local/bin/mysql /usr/local/mysql

Then run bundle install.

Reinstall libmysqlclient-dev with apt remove libmysqlclient-dev && apt install libmysqlclient-dev fixed for me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!