简体   繁体   中英

Rails installing mysql error

Hi I want to install mysql2 gem but it keeps failing.

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

Attached is the logs file: 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 install mysql2 -- --with-mysql-dir=c:\mysql-connector-c-6.1.1-win32

See details here:

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

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:

--

We've written a tutorial about this here

It's actually relatively simple to install the mysql2 gem if you do this :

  1. Install / unzip the MYSQL C-Connector 32 bit package on your system
  2. Install the gem, referencing the path without spaces
  3. Copy libmysql.dll to your Ruby installation

The first step is download the latest version of mysql 32-bit 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:

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

This should install the gem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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