Ruby mysql2 gem compiled for wrong mysql client library version

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

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.