mysql2 gem compiled for wrong mysql client library

2020-01-23 05:07发布

When try to connect to the mysql server through my rails application, I get the following error

D:/Program_Files/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': 
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.27. (RuntimeError)

How can I rectify it?

8条回答
We Are One
2楼-- · 2020-01-23 05:29

I discovered a completely different cause for this problem. I had been using the mysql gem. I built the mysql2 gem but I forgot to update my database.yml. With the mysql2 gem, it needs to say:

  development:
    adapter: mysql2

rather than

  development:
    adapter: mysql

The gem built, but I got the error when I next ran rake.

Obvious once you've seen it, but you get the same error message as discussed here!

By the way, the command to build the mysql2 gem on my machine was a bit more complicated than described above:

gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib"  --with-mysql-include="c:\mysql-connector-c-noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"
查看更多
啃猪蹄的小仙女
3楼-- · 2020-01-23 05:35

To Add to the existing answer. ( windows platform specifically )

Ruby really sucks on top of this. Rails should not actually care about the version of the connector or the mysql version. -- but that's my opinion.

In order to get this **ing thing working, you need 2 things. mysql2 gem and libmysql.dll and you need to match them up in terms of the version. (this caused confusion for me, because I can see the latest connector is 6.x while mysql is only 5.x, how should I match them up)

mysql2 gem. and when you install it you need to specify the connector.

     gem install mysql2 --platform=ruby -- 
     --with-mysql-lib="d:\mysql\lib" --with-mysql-include="d:\mysql\include"

it does not need to be connector downloaded from oracle. all you need is a mysql installation and the lib include folder underneath it. then put the libmysql.dll under railsinstaller bin folder.

if it didn't work to make you install mysql2 gem succesfully => for my case it is because my mysql is too old (why would ruby care that). so I get some latest mysql from oracle. use the lib include libmysql.dll under it. you don't really need to upgrade your database, you can keep it somewhere and continue to use it after you generated the 2 required components

my case: I use a very ancient mysql database and I am unwilling to upgrade it at the moment. so I back that database up and restored it later

查看更多
登录 后发表回答