如何在 Windows 上安装 mysql2 gem

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6258693/
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-09-15 17:00:29  来源:igfitidea点击:

How to install mysql2 gem on Windows

ruby-on-railswindowsrubygemsdevkit

提问by tiiin4

I'm using DevKit and XAMPP, and now I have to execute the following command:

我正在使用 DevKit 和 XAMPP,现在我必须执行以下命令:

gem install mysql2 -v 0.2.6 --platform=ruby -- --with-mysql-dir="x:\Prog
ram Files\mysql-5.5.11-winx64" --with-mysql-lib="x:\Program Files\mysql-5.5.11-winx64\lib" --with-my
sql-include="x:\Program Files\mysql-5.5.11-winx64\include" --without-opt-dir

However, XAMPP does not include a libor includefolder on its MySQL directory. What should I specify instead ?

但是,XAMPP在其 MySQL 目录中不包含libinclude文件夹。我应该指定什么?

Thanks

谢谢

回答by Corin

Here's the solution I used to get Ruby with the MySQL2 gem running on Windows 7 using XAMPP's MySQL installation.

这是我用来使用 XAMPP 的 MySQL 安装在 Windows 7 上运行的 MySQL2 gem 获取 Ruby 的解决方案。

At the Ruby command prompt run (make sure to update the path to wherever you've got XAMPP/MySQL installed):

在 Ruby 命令提示符下运行(确保更新安装 XAMPP/MySQL 的位置的路径):

gem install mysql2 -- --with-mysql-dir="C:\xampp\mysql\bin"

The output from this command includes:

此命令的输出包括:

=========================

==========================

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.

您已经安装了 mysql2 的二进制版本。它是使用 MySQL Connector/C 版本 6.0.2 构建的。建议使用完全相同的版本以避免潜在问题。

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

在构建此 gem 时,以下下载中提供了必要的 DLL 文件:

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

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

并将 lib\libmysql.dll 文件放在您的 Ruby bin 目录中,例如 C:\Ruby\bin

=========================

==========================

That is very important. Follow the instructions. Download the file, extract the libmysql.dll from the lib directory within the zip file. Copy said dll into the bin folder for your Ruby install. If you used RailsInstaller and selected the defaults, the directory will be something like C:\RailsInstaller\Ruby1.9.3\bin.

这是非常重要的。按照说明操作。下载文件,从 zip 文件中的 lib 目录中提取 libmysql.dll。将上述 dll 复制到您的 Ruby 安装的 bin 文件夹中。如果您使用 RailsInstaller 并选择了默认值,则该目录将类似于 C:\RailsInstaller\Ruby1.9.3\bin。

回答by konung

Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server

对于任何感兴趣的人来说,这是一个合适的解决方案,它不会弄乱您当前安装的 mysql 服务器

  1. Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)
  2. Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.
  3. Extract all the files from the zip file into the folder you just created.
  4. now run this command

    gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'

  1. 使用 mysql server 5.1 而非 msi 下载一个 zip 文件。确保它是 32 位而不是 64 位。(从这里
  2. 由于没有安装程序文件,请创建一个文件夹 c:\mysql-gem-install - 完成后您可以将其删除。
  3. 将 zip 文件中的所有文件解压缩到您刚刚创建的文件夹中。
  4. 现在运行这个命令

    gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'

I just installed mysql2 gem v. 0.3.7

我刚刚安装了 mysql2 gem v. 0.3.7

回答by tiiin4

I found the solution here:

我在这里找到了解决方案:

rails 3 not working with windows 7

导轨 3 不适用于 Windows 7

回答by André Herculano

What solved my problem was:

解决我的问题的是:

  1. Downloaded the lastest MySQL Installerfor windows 7 32 bits
  2. Installed the gem with the following command: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'
  1. 下载了适用于 Windows 7 32 位的最新 MySQL安装程序
  2. 使用以下命令安装 gem: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'

One pitfall to be aware of is that I changed the backslashes (\) to normal slashes (/). I've tried the same procedure with backslashes and it didn't work.

要注意的一个陷阱是我将反斜杠 (\) 更改为普通斜杠 (/)。我已经用反斜杠尝试了相同的程序,但没有奏效。

The installer already includes the C connectors for MySQL at MySQL Connector C 6.1 6.1.2directory. Therefore, passing only the --with-mysql-dirparameter without the --with-mysql-libor --with-mysql-includeparameters, makes the gem to look at the same directory for the liband includedirectories

安装程序已在MySQL Connector C 6.1 6.1.2目录中包含 MySQL 的 C 连接器。因此,只传递--with-mysql-dir没有--with-mysql-libor--with-mysql-include参数的参数,会使 gem 在同一个目录中查找libandinclude目录

回答by Erwin Kaddy

Thanks nick. I got it working too on my windows 8 (64bit). I got MySQL connector from this page: http://dev.mysql.com/downloads/connector/c/. Download and Run the installer. After that use the command below:

谢谢尼克。我在 Windows 8(64 位)上也能正常工作。我从这个页面得到了 MySQL 连接器:http: //dev.mysql.com/downloads/connector/c/。下载并运行安装程序。之后使用以下命令:

gem install mysql2 -- '--with-mysql-lib="C:\Program Files\MySQL\MySQL Connector C 6.1\lib" --with-mysql-include="C:\Program Files\MySQL\MySQL Connector C 6.1\include"'

Now it's working

现在它正在工作

回答by user674158

You may copy libmysql.dll from the lib subdirectory of your MySQL or MySQL connector directory into your ruby\bin directory ,and libmysql.dll would be located at c:\mysql-connector-c-6.1.1-win32\lib.

您可以将 libmysql.dll 从 MySQL 或 MySQL 连接器目录的 lib 子目录复制到 ruby​​\bin 目录,libmysql.dll 将位于 c:\mysql-connector-c-6.1.1-win32\lib。

回答by Cereal

With RubyInstaller2, and the MSYS toolchain, all you have to do to install the mysql2 gem is gem install mysql2 --platform=ruby

使用 RubyInstaller2 和 MSYS 工具链,安装 mysql2 gem 所需要做的就是 gem install mysql2 --platform=ruby

This will automatically download and install the required libraries, and then build the gem from source.

这将自动下载并安装所需的库,然后从源代码构建 gem。

回答by bassneck

I'm not sure, how XAMPP is organized, but to build the gem, you could download the sameversion of mysql from their siteand point devkit there. After that, the gem should work fine with XAMPP as well.

我不确定 XAMPP 是如何组织的,但是要构建 gem,您可以从他们的站点下载相同版本的 mysql并将 devkit 指向那里。之后,gem 也应该与 XAMPP 一起正常工作。