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

发布于 2024-12-25 00:49:28 字数 302 浏览 8 评论 0原文

当尝试通过我的 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)

如何纠正?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

甜心 2025-01-01 00:49:28

卸载并重新安装 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.

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 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.
粉红×色少女 2025-01-01 00:49:28

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

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

当我运行 bundle exec rake db:create 时,我收到了与您相同的错误消息,我想“嘿,当我从最新的 MySQL 版本获取客户端库时,它怎么会过时呢?”

当您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

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

参考链接

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 bin folder.

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?"

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:

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

回忆躺在深渊里 2025-01-01 00:49:28

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

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

对于 Ruby 1.9.2:

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

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

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

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

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/

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

for 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)

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.

望她远 2025-01-01 00:49:28

我遇到了这样的问题:

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

对我来说,问题是我的计算机上安装了两个版本:5.5.29 和 5.6.17。我不知道怎么办。当我捆绑时它自动选择了5.5.29版本。我卸载了那个,然后重新安装了我的 gem,这解决了问题。

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.

寄与心 2025-01-01 00:49:28

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

  development:
    adapter: mysql2

而不是

  development:
    adapter: mysql

The gembuilt,但是当我下次运行 rake 时出现错误。

一旦您看到它,就很明显了,但是您会收到与此处讨论的相同的错误消息!

顺便说一句,在我的机器上构建 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"

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"
小帐篷 2025-01-01 00:49:28

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

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.

游魂 2025-01-01 00:49:28

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

为了使其正常工作,您需要两件事。 mysql2 gemlibmysql.dll 并且您需要在版本方面匹配它们。

mysql2 gem:安装时需要指定连接器。

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

不需要是从oracle下载的连接器。您所需要的只是 mysql 安装及其下面的 lib/include 文件夹。然后将libmysql.dll放在railsinstaller bin文件夹下。

如果它不能让你成功安装 mysql2 gem => 对于我的情况,那是因为我的 mysql 太旧了。所以我从oracle那里得到了最新的mysql。使用其下的lib include libmysql.dll您实际上并不需要升级数据库,您可以将其保存在某个地方,并在生成 2 个所需组件后继续使用它

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

In order to get this working, you need 2 things. The mysql2 gem and libmysql.dll and you need to match them up in terms of the version.

mysql2 gem: 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 the 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. So I get the 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

棒棒糖 2025-01-01 00:49:28

我遇到了同样的问题,并且解决了以下问题:

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

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

3 :: 旋转一个运行命令bundle install

并准备好,解决了!

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

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/

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

3 :: Volve one to run the command bundle install

and ready , solved !

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

眼角的笑意。 2025-01-01 00:49:28

我在 Debian v 12 和 Rails 3 上遇到了同样的问题。尝试了一切,但没有任何效果最终这有效,将 Gemfile 更改为:

gem 'mysql2', git: 'https://github.com/makandra/mysql2', branch: '0.3.x-lts' # for Rails 3.x

https://makandracards.com/makandra/515130-fix-mysql2-error-in Correct-mysql-client-library-version

I had same problem on Debian v 12 with Rails 3. Tried everything, and nothing worked finaly this worked, changed Gemfile to:

gem 'mysql2', git: 'https://github.com/makandra/mysql2', branch: '0.3.x-lts' # for Rails 3.x

got his from https://makandracards.com/makandra/515130-fix-mysql2-error-incorrect-mysql-client-library-version

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文