简体   繁体   English

在 Windows 上安装 MySQL2 Gem

[英]Installing MySQL2 Gem on Windows

I was having some issues getting the mysql2 gem to install on my Windows 8.1 machine.我在 Windows 8.1 机器上安装 mysql2 gem 时遇到了一些问题。 I followed the instructions in this post:我按照这篇文章中的说明进行操作:

Ruby MYSQL2 gem installation on windows 7 在 Windows 7 上安装 Ruby MYSQL2 gem

to install the mysql2 gem, and I did not get any error messages.安装mysql2 gem,我没有收到任何错误消息。

I followed this with the我跟着这个

bundle install 

command, and confirmed that the following gems are installed (using bundle show), confirming that I have the following gems installed:命令,并确认安装了以下 gems(使用 bundle show),确认我安装了以下 gems:

Using devise (3.2.2)
Using mysql2 (0.3.14)

Then I tried doing:然后我尝试这样做:

rails generate devise:install

and this is what I got:这就是我得到的:

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `require': 126: The specified module could not be found.   
- C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2/mysql2.so (LoadError)
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/lib/mysql2.rb:8:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `block in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.5.1/lib/bundler.rb:131:in `require'
    from C:/Users/Joseph/googledrive/projects/rails/test_new_devise/config/application.rb:7:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:43:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/commands.rb:43:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Any ideas?有任何想法吗?

Solution:解决方案:

The answer is a combination of two answers from stackoverflow, plus modifications.答案是来自 stackoverflow 的两个答案的组合,加上修改。 The stackoverflow references are:堆栈溢出参考是:

Ruby MYSQL2 gem installation on windows 7 ...mysql2/mysql2.so: [BUG] Segmentation fault ruby 2.0.0p247 在 Windows 7 上安装 Ruby MYSQL2 gem ...mysql2/mysql2.so: [BUG] 分割错误 ruby​​ 2.0.0p247

Bottom line: to get mysql2 working in a 64 bit environment with Ruby 2 on Windows 8.1, you need to do the following:底线:要让 mysql2 在 Windows 8.1 上的 Ruby 2 的 64 位环境中工作,您需要执行以下操作:

  1. Clean up: the reason you're here is that you're probably been trying to install this gem, and it has failed, so you have some cleanup to do: gem uninstall mysql2清理:你在这里的原因是你可能正在尝试安装这个 gem,但它失败了,所以你有一些清理工作要做: gem uninstall mysql2

  2. Download Ruby 2.0 64 bit for Windows:下载适用于 Windows 的 Ruby 2.0 64 位:

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353-x64.exe?direct http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353-x64.exe?direct

  1. Run the installer.运行安装程序。 Note the directory it installs to, and make sure it's in the User PATH.注意它安装到的目录,并确保它在用户路径中。 go to

    Control Panel > System and Security > System - Advanced System Settings > Environment Variables

and make sure the path to the bin directory of the ruby install directory is in the PATH environment variable for the LOCAL user (it's also OK if it's in the SYSTEM Path environment variable)并确保ruby安装目录的bin目录的路径在LOCAL用户的PATH环境变量中(如果在SYSTEM Path环境变量中也可以)

  1. Download the Ruby 2 64 bit Dev Kit:下载 Ruby 2 64 位开发工具包:

http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

  1. Run the installer and note the location of the install directory.运行安装程序并记下安装目录的位置。 The instructions say that once you're done with the install, you need to run the devkitvars.bat file to set the environment variables.说明说完成安装后,您需要运行 devkitvars.bat 文件来设置环境变量。 This DOES NOT work for Windows 8.1.这不适用于 Windows 8.1。 You need to repeat the instructions to set the local path described in #2 above, to set the path environment variable for the local user to add the ruby dev kit bin directory, and the ruby dev kit mingw bin directory.需要重复上面#2中设置本地路径的说明,为本地用户设置路径环境变量,添加ruby dev kit bin目录,以及ruby dev kit mingw bin目录。 For example, if the dev kit was installed to c:\\ruby2devkit, and you installed ruby2 to the C:\\Ruby200-x64 directory, then your edit your path statement to look like this:例如,如果开发工具包安装到 c:\\ruby2devkit,而您将 ruby​​2 安装到 C:\\Ruby200-x64 目录,那么您将路径语句编辑为如下所示:

     C:\\Ruby200-x64\\bin;C:\\ruby2-devkit\\bin;c:\\ruby2-devkit\\mingw\\bin
  2. Next you need to install the mysql-connector.接下来你需要安装mysql-connector。 DO NOT download and run the self-installer.请勿下载并运行自安装程序。 Instead, download the zip file and unpack it.相反,下载 zip 文件并解压它。 Note the directory you unpacked it to (for the purposes of this post, let's assume you unpacked it to c:\\mysql-connector:请注意您将其解压到的目录(出于本文的目的,假设您将其解压到 c:\\mysql-connector:

http://dev.mysql.com/downloads/file.php?id=450612 http://dev.mysql.com/downloads/file.php?id=450612

  1. The libmysql.lib included in the MySQL Connector 64 bit is not compatible with the mingw64-gcc compiler. MySQL 连接器 64 位中包含的 libmysql.lib 与 mingw64-gcc 编译器不兼容。 You need to generate mingw64 compatible libmysql.lib file.您需要生成 mingw64 兼容的 libmysql.lib 文件。

  2. Download the tools you need下载您需要的工具

    https://structure-svm-map.googlecode.com/files/svm-map-win.zip https://structure-svm-map.googlecode.com/files/svm-map-win.zip

  3. Unzip this file to a local directory, let's assume that you unzipped it to c:\\svm-map将此文件解压缩到本地目录,假设您将其解压缩到 c:\\svm-map

  4. Edit the PATH environment path, as described earlier, to now look like this:如前所述,编辑 PATH 环境路径,现在看起来像这样:

     C:\\Ruby200-x64\\bin;C:\\ruby2-devkit\\bin;c:\\ruby2-devkit\\mingw\\bin;c:\\svm-map;C:\\svm-map\\python-mingw-lib
  5. Generate the new mysql libraries:生成新的 mysql 库:

     (make sure you're running as administrator) cd c:\\mysql-connector\\lib gendef.exe libmysql.dll dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib copy libmysql.dll C:\\Ruby200-x64\\bin copy libmysql.lib C:\\Ruby200-x64\\bin
  6. Install the gem as follows (note the use of forward slashes instead of backslashes, it will fail if you use backslashes):安装 gem 如下(注意使用正斜杠而不是反斜杠,如果使用反斜杠会失败):

    gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector/"' gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector/"'

Hope this helps, and hopefully someone will pay attention to the few Windows 8.1 users who want to do Ruby on Rails development.希望这会有所帮助,希望有人会关注那些想要进行 Ruby on Rails 开发的少数​​ Windows 8.1 用户。

When you installed the mysql2 , did you download the lib files it needs?当您安装mysql2 ,您是否下载了它需要的 lib 文件?


I've not installed it on Windows 8, but Windows 7 needs to have this file to give mysql the dependencies requires to help it work.我没有在 Windows 8 上安装它,但 Windows 7 需要有这个文件来为 mysql 提供帮助它工作所需的依赖项。 You can see various tutorials on how to do this, and I'll outline a simple overview here:您可以查看有关如何执行此操作的各种教程,我将在此处概述一个简单的概述:

- Unzip the mysql connector file : - 解压mysql 连接器文件

C:\\mysql-connector-c-6.1.3-win32\\ (or similar path WITHOUT any spaces) C:\\mysql-connector-c-6.1.3-win32\\ (或类似路径,不带任何空格)

- Run the mysql2 gem installer again: - 再次运行mysql2 gem 安装程序:

gem uninstall mydsql
gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include" --with-mysql-dir="C:\mysql-connector"'

Bottom line is I think your mysql2 gem isn't loading the files it requires to run, and probably doesn't show an error because it's Windows 8底线是我认为您的mysql2 gem 没有加载运行所需的文件,并且可能没有显示错误,因为它是 Windows 8

I hope this will be of help when trying to install mysql2 using MariaDB on a Windows 10 machine.我希望这在尝试在Windows 10机器上使用MariaDB安装mysql2时会有所帮助。

I had a lot of issues trying the use the connector library for some reason.由于某种原因,我在尝试使用连接器库时遇到了很多问题。 And in addition the libraries I could download were version 6 and the version of MariaDB I was using was using version 10 of the libraries.此外,我可以下载的库是第 6 版,而我使用的 MariaDB 版本使用的是第 10 版的库。

I first downloaded and installed MariaDB.我首先下载并安装了 MariaDB。

I used the command我使用了命令

gem install mysql2 --platform=ruby -- --with-mysql-lib="path_to:\MariaDB 10.5\"

This compiled and installed the gem without any issues.这编译并安装了 gem,没有任何问题。

In the database.yml在数据库.yml

default: &default adapter: mysql2 encoding: utf8 reconnect: false database: DBname pool: 5 username: DBuser password: DBpassword socket: tmp/mysql.sock默认:&default 适配器:mysql2 编码:utf8 重新连接:false 数据库:DBname 池:5 用户名:DBuser 密码:DBpassword 套接字:tmp/mysql.sock

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM