简体   繁体   English

Rails安装mysql错误

[英]Rails installing mysql error

Hi I want to install mysql2 gem but it keeps failing. 嗨,我想安装mysql2 gem,但它一直失败。

C:\Users\HuiHui\Documents\ruby 2.0.0>gem install mysql2 -v '0.3.11'
Fetching: mysql2-0.3.11.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby200-x64/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby200-x64/bin/ruby
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/
        --with-libmysqllib
        --without-libmysqllib


Gem files will remain installed in C:/RailsInstaller/Ruby200-x64/lib/ruby/gems/2
.0.0/gems/mysql2-0.3.11 for inspection.
Results logged to C:/RailsInstaller/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-
0.3.11/ext/mysql2/gem_make.out

it keeps having the same problem despite changing versions, uninstalling and installing without any version and all. 尽管更改了版本,没有任何版本和全部进行卸载和安装,但它仍然存在相同的问题。 Can someone shed some light on this? 有人可以阐明这一点吗? I am doing things on a Windows.. 我正在Windows上做事。

Attached is the logs file: https://www.dropbox.com/s/7rg6eibhhvlf21r/mkmf.log 附件是日志文件: https : //www.dropbox.com/s/7rg6eibhhvlf21r/mkmf.log

EDIT 编辑

After trying the tutorial from medium, I've got this error. 在尝试了中等水平的教程之后,我遇到了这个错误。

C:\Users\HuiHui\sutdweb>gem install mysql2 -- --with-mysql-dir=c:\mysql-connecto
r-c-6.1.5-win32
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-dir=c:\mysql-connector-c-6.1.5-wi
n32'
This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby200-x64/bin/ruby.exe extconf.rb --with-mysql-dir=c:\my
sql-connector-c-6.1.5-win32
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using --with-mysql-dir=c:\mysql-connector-c-6.1.5-win32
-----
checking for main() in -llibmysql... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby200-x64/bin/ruby
        --with-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/
        --with-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib


Gem files will remain installed in C:/RailsInstaller/Ruby200-x64/lib/ruby/gems/2
.0.0/gems/mysql2-0.3.16 for inspection.
Results logged to C:/RailsInstaller/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-
0.3.16/ext/mysql2/gem_make.out

In your response to how to specify configuration options with gem and mysql2, it's something like this: 在您对如何使用gem和mysql2指定配置选项的回答中,类似于以下内容:

gem install mysql2 -- --with-mysql-dir=c:\mysql-connector-c-6.1.1-win32

See details here: 在这里查看详细信息:

https://github.com/brianmario/mysql2 https://github.com/brianmario/mysql2

Can someone shed some light on this? 有人可以阐明这一点吗?

Sure - the problem is to do with Windows' compatibility with the MYSQL2 gem - by default, Windows does not come with the MYSQL header files which are required to allow the gem to connect with MYSQL 当然-问题与Windows与MYSQL2 gem的兼容性有关-默认情况下,Windows不附带允许该gem与MYSQL连接所需的MYSQL头文件

In order to install it, you need to install the MYSQL C-Connector package, and use it to give your gem the C++ header files it needs to run: 为了安装它,您需要安装MYSQL C-Connector软件包,并使用它为gem提供运行所需的C ++头文件:

-- -

We've written a tutorial about this here 我们在这里写了一个关于这个的教程

It's actually relatively simple to install the mysql2 gem if you do this : 如果这样做,安装mysql2 gem实际上相对简单:

  1. Install / unzip the MYSQL C-Connector 32 bit package on your system 在系统上安装/解压缩MYSQL C-Connector 32位软件包
  2. Install the gem, referencing the path without spaces 安装gem,引用路径中没有空格
  3. Copy libmysql.dll to your Ruby installation libmysql.dll复制到您的Ruby安装中

The first step is download the latest version of mysql 32-bit c-connector. 第一步是下载最新版本的mysql 32位c-connector。 Unzip / install into a path without spaces - this is essential. 解压缩/安装到没有空格的路径中-这是必不可少的。

The second step is to use the following command to install the gem, referencing the c-connector files: 第二步是使用以下命令安装cem,并引用c-connector文件:

gem install mysql2 --platform=ruby -- ‘--with-mysql-dir=”C:\mysql-connector-path”’

Finally, you should copy the libmysql.dll file from the /bin folder of your C-Connector files to the /bin directory of Ruby 最后,您应该将C-Connector文件的/bin文件夹中的libmysql.dll文件复制到Ruby/bin目录中。

This should install the gem 这应该安装宝石

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

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