mysql2 icon indicating copy to clipboard operation
mysql2 copied to clipboard

Error while installing mysql2 (0.5.4) with Ruby 3.1.2p20 on Windows

Open MukendiMputu opened this issue 2 years ago • 5 comments

Hi, I'm having the following error while installing mysql2 gem on my windows machine:

Installing mysql2 0.5.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/mysql2-0.5.4/ext/mysql2
C:/Ruby31-x64/bin/ruby.exe -I C:/Ruby31-x64/lib/ruby/3.1.0 -r
./siteconf20220829-15704-4w8qmw.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
*** 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:/Ruby31-x64/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysqlclient-dir
        --without-mysqlclient-dir
        --with-mysqlclient-include
        --without-mysqlclient-include=${mysqlclient-dir}/include
        --with-mysqlclient-lib
        --without-mysqlclient-lib=${mysqlclient-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `block in find_library': undefined
method `split' for nil:NilClass (NoMethodError)

paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)}
                                   ^^^^^^
    from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `each'
    from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `flat_map'
    from C:/Ruby31-x64/lib/ruby/3.1.0/mkmf.rb:1086:in `find_library'
    from extconf.rb:103:in `<main>'

Does anyone know a fix for this? Thanks for any helping advice

MukendiMputu avatar Aug 29 '22 18:08 MukendiMputu

I've hit the same problem on one of my systems (debian, Ruby 3.1.2).

ragesoss avatar Sep 15 '22 20:09 ragesoss

I think the error message it shows is misleading on Ruby 3.1.2. When I tried installing it on Ruby 2.5.0, the error message instead indicated that I should install libmariadb-dev or libmysqlclient-dev. I did the first one (which was out of date on my system) and after that I was able to install Ruby 3.1.2.

ragesoss avatar Sep 15 '22 20:09 ragesoss

Gemfile:

ruby "3.1.2"
gem "rails", "~> 7.0.4"
gem "mysql2", "~> 0.5"
ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [i386-mingw32]

had the same error on clean rails project, but the problem was, that it didn't found mysql2 dir, so:

mysql --version
h:\wamp64\bin\mysql\mysql5.7.35\bin\mysql.exe  Ver 14.14 Distrib 5.7.35, for Win64 (x86_64)

gem install mysql2 --platform=ruby -- '--with-mysql-lib="H:\wamp64\bin\mysql\mysql8.0.21\lib" --with-mysql-include="H:\wamp64\bin\mysql\mysql8.0.21\include" --with-mysql-dir="H:\wamp64\bin\mysql\mysql8.0.21"'

Fetching mysql2-0.5.4.gem
Temporarily enhancing PATH for MSYS/MINGW...
Using msys2 packages: mingw-w64-i686-libmariadbclient
Building native extensions with: '--with-mysql-lib=H:\wamp64\bin\mysql\mysql8.0.21\lib --with-mysql-include=H:\wamp64\bin\mysql\mysql8.0.21\include --with-mysql-dir=H:\wamp64\bin\mysql\mysql8.0.21'
This could take a while...
Successfully installed mysql2-0.5.4
Parsing documentation for mysql2-0.5.4
Installing ri documentation for mysql2-0.5.4
Done installing documentation for mysql2 after 0 seconds
1 gem installed

Faq avatar Jan 01 '23 21:01 Faq

Dear developers,

help to install Mysql2 component for Ruby. I tried to install from MySQLConnector, as user Faq, but I get an error while executing the require 'mysql2' script that it was not found. The standard method, as in the documentation, also does not work:

  1. Operating System: Windows 11 Home, Version: 22H2, Build: 22621.1485
  2. Ruby version: 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
  3. I type the command: C:\Ruby32-x64\bin>gem install mysql2
  4. I get the error: *** extconf.rb failed *** [skip] mkmf.rb:1083:in block in find_library': undefined method split' for nil:NilClass (NoMethodError) How do I fix mysql2 component issue?

alex1543 avatar Apr 04 '23 05:04 alex1543

Installing MySQL2 for Ruby is viable, but when downloading the full archive mysql-8.0.32-winx64.zip and running the command:

C:\Ruby32-x64\bin>gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\Ruby32-x64\mysql-8.0.32-winx64\lib" --with- mysql-include="C:\Ruby32-x64\mysql-8.0.32-winx64\include" --with-mysql-dir="C:\Ruby32-x64\mysql-8.0.32-winx64"'

Developers, thank you very much for your help!

alex1543 avatar Apr 04 '23 18:04 alex1543