mysql2 gem 为错误的 mysql 客户端库编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8740868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:14:54  来源:igfitidea点击:

mysql2 gem compiled for wrong mysql client library

mysqlruby-on-railswindowsmysql2

提问by Rahul

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

当尝试通过我的 rails 应用程序连接到 mysql 服务器时,我收到以下错误

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?

我该如何纠正?

回答by chrislopresto

Uninstalling and reinstalling the gem will often solve this issue with no need to download and move files around by hand. From your rails app directory:

卸载并重新安装 gem 通常可以解决此问题,而无需手动下载和移动文件。从您的 rails 应用程序目录:

> gem uninstall mysql2

You have requested to uninstall the gem:
    mysql2-0.3.11
database_cleaner-0.9.1 depends on [mysql2 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  Y
Successfully uninstalled mysql2-0.3.11

> bundle install

Fetching gem metadata from http://rubygems.org/......
Fetching gem metadata from http://rubygems.org/..
Using rake (0.9.2)
Using i18n (0.6.1)
... <SNIP> ...
Installing mysql2 (0.3.11) with native extensions
... <SNIP> ...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

回答by antinome

I had the same problem as you, or at least the symptom was the same.

我和你有同样的问题,或者至少症状是一样的。

Background: I was using Rails 3, the mysql2 gem, and MySQL community server version 5.5.21 (32-bit) installed locally on my Windows machine. I grabbed the client library (libmysql.dll) from the MySQL installation and copied it to my ruby installation's binfolder.

背景:我使用 Rails 3、mysql2 gem 和 MySQL 社区服务器版本 5.5.21(32 位)安装在我的 Windows 机器上。我libmysql.dll从 MySQL 安装中获取客户端库 ( ) 并将其复制到我的 ruby​​ 安装bin文件夹中。

When I ran bundle exec rake db:create, I got the same error message as you and I thought "Hey, how can the client library be outdated when I got it from the latest MySQL release?"

当我运行时bundle exec rake db:create,我得到了和你一样的错误信息,我想“嘿,当我从最新的 MySQL 版本中得到它时,客户端库怎么会过时?”

There's a helpful message that is shown when you gem install mysql2. Unfortunately, if you install the gem with Bundler, Bundler eats the message. Here it is:

当您使用gem install mysql2. 不幸的是,如果您使用 Bundler 安装 gem,Bundler 会吃掉消息。这里是:

=========================================================================
You've installed the binary version of mysql2. It was built using MySQL 
Connector/C version 6.0.2. It's recommended to use the exact same version
to avoid potential issues.

At the time of building this gem, the necessary DLL files where available
in the following download:

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

And put lib\libmysql.dll file in your Ruby bin directory, for example
C:\Ruby\bin

Following these instructions solved the problem for me.

按照这些说明为我解决了这个问题。

Referenced link

参考链接

回答by user482594

If you are using 64bit version of mysql and 32bit version of ruby, then check this solution on http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/

如果您使用的是 64 位版本的 mysql 和 32 位版本的 ruby​​,请在http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using上查看此解决方案 -ruby-with-it/

You basically have to download a single connector from mysql website, and compile mysql or mysql2 with connector you downloaded.

您基本上必须从 mysql 网站下载单个连接器,并使用您下载的连接器编译 mysql 或 mysql2。

for Ruby 1.9.2:

对于 Ruby 1.9.2:

gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32

for Ruby 1.9.3: (showing mysql2 variant)

对于 Ruby 1.9.3:(显示 mysql2 变体)

gem pristine mysql2 -- --with-mysql-config=C:\mysql-connector-c-noinstall-6.0.2-win32    

Note the use of forward slashes for the directory where MySQL Connector/C was extracted.

请注意对提取 MySQL Connector/C 的目录使用正斜杠。

回答by Victor Kmita

I had an issue just like this:

我遇到了这样的问题:

Incorrect MySQL client library version! This gem was compiled for 5.5.29 but the client library is 5.6.17.

The issue for me was that I had both versions, 5.5.29 and 5.6.17, installed on my machine. I have no idea how. When I bundled it automatically chose the 5.5.29 version. I uninstalled that one and then reinstalled my gem and that fixed the issue.

我的问题是我的机器上安装了 5.5.29 和 5.6.17 两个版本。我不知道如何。当我捆绑它时,它自动选择了 5.5.29 版本。我卸载了那个,然后重新安装了我的 gem 并解决了这个问题。

回答by zinking

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

添加到现有答案。(特别是windows平台)

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.

Ruby 真的很糟糕。Rails 实际上不应该关心连接器的版本或 mysql 版本。——但这是我的看法。

In order to get this **ing thing working, you need 2 things. mysql2 gemand libmysql.dlland 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)

为了让这个 **ing 的东西工作,你需要两件事。mysql2 gem并且libmysql.dll您需要在版本方面匹配它们。(这让我很困惑,因为我可以看到最新的连接器是 6.x,而 mysql 只有 5.x,我应该如何匹配它们

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

mysql2 宝石。安装时需要指定连接器。

     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 libincludefolder underneath it. then put the libmysql.dllunder railsinstaller binfolder.

它不需要是从 oracle 下载的连接器。你所需要的只是一个 mysql 安装和libinclude它下面的文件夹。然后把libmysql.dllrailsinstaller bin文件夹。

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 libincludelibmysql.dllunder 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

如果它无法让您成功安装 mysql2 gem =>就我而言,那是因为我的 mysql 太旧了(为什么 ruby​​ 会关心它)。所以我从oracle 得到了一些最新的mysql。libincludelibmysql.dll在它下面使用 。你真的不需要升级你的数据库,你可以把它放在某个地方,并在你生成 2 个必需的组件后继续使用它

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

我的情况:我使用了一个非常古老的 mysql 数据库,目前我不愿意升级它。所以我备份该数据库并稍后恢复它

回答by user2315251

in my case on windows, incorrectly copied libmysql.dll from MySQL Server 5.5 directory to ruby200/bin. correct is to copy libmysql.dll from mysql-connector-c-noinstall-6.0.2-win32.

就我而言,在 Windows 上,错误地将 libmysql.dll 从 MySQL Server 5.5 目录复制到 ruby​​200/bin。正确的是从mysql-connector-c-noinstall-6.0.2-win32复制libmysql.dll。

回答by user1208639

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:

我发现了这个问题的一个完全不同的原因。我一直在使用 mysql gem。我构建了 mysql2 gem,但我忘记更新我的 database.yml。用mysql2 gem,需要说:

  development:
    adapter: mysql2

rather than

而不是

  development:
    adapter: mysql

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

gem 已构建,但在我下次运行 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:

顺便说一句,在我的机器上构建 mysql2 gem 的命令比上面描述的要复杂一些:

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"

回答by Yulian D.

I had the same problem , and I have solved the follows:

我遇到了同样的问题,我已经解决了以下问题:

1 ::Download the zip the following link: https://dev.mysql.com/downloads/connector/c/

1 ::通过以下链接下载 zip:https: //dev.mysql.com/downloads/connector/c/

2 ::decompress the file ( libmysql.dll) in the " Provider" folder of project.

2 ::解压项目“ Provider”文件夹中的文件(libmysql.dll)。

3 ::Volve one to run the command bundle install

3 ::Volve one 运行命令bundle install

and ready , solved !

准备好了,解决了!

https://dev.mysql.com/downloads/connector/c/

https://dev.mysql.com/downloads/connector/c/