30

I'm using ruby 2.3, and in the gemfile, I've got the mysql2 gem listed. But when I try to run rake db:migrate, I get the following:

/Users/me/.gem/ruby/2.3.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `require': incompatible library version - /Users/me/.gem/ruby/2.3.0/gems/mysql2-0.4.2/lib/mysql2/mysql2.bundle (fatal)

I can't seem to get around this one. I've installed Mysql 5.7 with Homebrew, tried updating the bundle, uninstalling and reinstalling the mysql2 gem, all to no avail.

How can I get this resolved?

croceldon
  • 4,511
  • 11
  • 57
  • 92

6 Answers6

52

I ended up solving this with gem pristine --all

croceldon
  • 4,511
  • 11
  • 57
  • 92
8

I have solved this with gem pristine mysql2 followed by spring stop.

joe
  • 192
  • 1
  • 10
0

I experienced the same issue. I had ruby 2.3.4 installed and using rails 4.6.2.

There were two issues causes and the support team of the hosting company I was using helped me resolve the issue.

The first was that the mysql2 lib that was installed was, by default, linked to ruby 1.8 instead of ruby 2

# lld ../2.2.0/mysql2-0.4.4/mysql2/mysql2.so
... 
...
libruby.so.1.8 => /usr/lib64/libruby.so.1.8 (0x00007f2af1f8a000)
...

Second issue was to compile the lib with the installed mysql server config

So mysql2 gem had to be uninstalled and re-installed with the right ruby lib and compiled with the right mysql config.

Below are the commands.

gem uninstall mysql2
gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config --with-opt-lib=/where/my/ruby22/lib_was_located/
mwangi
  • 1,616
  • 1
  • 20
  • 23
0

I experienced this problem moving to Ubuntu 16.04

The following did the trick

sudo apt-get install g++
sudo apt-get install build-essential
Community
  • 1
  • 1
user3487016
  • 109
  • 2
  • 2
  • 6
0

running sudo gem pristine mysql2 did not work for me.

I had to uninstall and reinstall the mysql2 gem.

Krishna Vedula
  • 1,643
  • 1
  • 27
  • 31
0

The only thing that worked for me was

gem install nokogiri -v 1.10.2

after that, it was fine.

newtron54
  • 141
  • 1
  • 4