0

I am trying to install the mysql2 gem so that I can navigate mysql databases with ruby and mysql combined. I typed in the terminal: gem install mysql2 - and it did this:

lr>gem install mysql2
Temporarily enhancing PATH for MSYS/MINGW...
Using msys2 packages: mingw-w64-x86_64-libmariadbclient
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    current directory: C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3/ext/mysql2
C:/Ruby30-x64/bin/ruby.exe -I C:/Ruby30-x64/lib/ruby/3.0.0 -r ./siteconf20210201-7628-g2k8zu.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... 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:/Ruby30-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:/Ruby30-x64/lib/ruby/3.0.0/mkmf.rb:1050:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError)
        from C:/Ruby30-x64/lib/ruby/3.0.0/mkmf.rb:1050:in `collect'
        from C:/Ruby30-x64/lib/ruby/3.0.0/mkmf.rb:1050:in `find_library'
        from extconf.rb:87:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  C:/Ruby30-x64/lib/ruby/gems/3.0.0/extensions/x64-mingw32/3.0.0/mysql2-0.5.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mysql2-0.5.3 for inspection.
Results logged to C:/Ruby30-x64/lib/ruby/gems/3.0.0/extensions/x64-mingw32/3.0.0/mysql2-0.5.3/gem_make.out

This would help if someone gave me a solution to this problem. If I find a solution I'll post up here. Thanks!

Dev89
  • 35
  • 5
  • Yeah, getting mysql2 work on windows was the main reason i moved to linux. I am a happy man now, highly recommended! – BroiSatse Feb 01 '21 at 23:13

2 Answers2

0

Do You have MySQL installed already? If not install it first and try again. You can also check this Installing MySQL2 Gem on Windows

0

On windows, if you want to build gems with native extensions, you need RubyInstaller with DevKit/MSYS. Basically it contains tools to compile C code and package it in such a way your ruby version can use it.

user124
  • 1,632
  • 1
  • 11
  • 11