Can't Install MySQL2 0.3.16 gem on Ruby - mysql

I'm having a bunch of problems installing the mysql2 gem on Ruby, I've tried a lot of guides, but nothing seems to be working... Here's the error when I try to install it, without any extra commands.
C:\Users\Julián>gem install mysql2 --no-rdoc --no-ri
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:/Ruby200-x64/bin/ruby.exe extconf.rb
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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:/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-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql
2-0.3.16 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/extensions/x64-mingw32/2.0.
0/mysql2-0.3.16/gem_make.out
I'm really stumped, I tried to find a solution around here but couldn't find anything. I tried installing MySQL connectors and setting with-mysql-lib commands. Please help!

Since it appears you're using Windows, you need to consider you have to install the MYSQL C-Connector header files to get it to work
We've written a tutorial about this here
--
You'll want to use the following steps:
Install the MYSQL C-Connector files (without any spaces in path)
Install the MYSQL2 gem again (with correct path references)
Copy lbmysql.dll to your ruby/bin folder
Firstly, you'll want to downlaod the MYSQL C-Connector files:
It has to be 32-bit C-Connector
Once you've installed this into a path with no spaces, you can then use the mysql2 installation command again, with config options:
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-path"'
After this, you can then transfer libmysql.dll from your mysql files to your ruby/bin directory:

in a terminal.. First do a ‘locate mysql_config’ and then replace the path in the following command with where that file is.
gem install mysql2 --no-rdoc --no-ri --with-mysql-config=path

Related

Error while installing mysql gem in terminal

When I attempt to run the following in Terminal, I receive an error that prevents the installation of mysql gem:
I run:
sudo gem install mysql
I receive the following error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/Users/(myuseraccount)/.rbenv/versions/2.1.5/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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=/Users/(myuseraccount)/.rbenv/versions/2.1.5/bin/ruby
--with-mysql-config
--without-mysql-config
--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-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
extconf failed, exit code 1
Gem files will remain installed in /Users/(myuseraccount)/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/mysql-2.9.1 for inspection.
Results logged to /Users/(myuseraccount)/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/mysql-2.9.1/gem_make.out
Please tell me if you know how I can fix this error and install the mysql gem
Install mysql2 gem rather than mysql and be sure to have MySql installed before install the gem:
brew install mysql
gem install mysql2
bundle install
Error was:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
..................
An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue.
Make sure that gem install mysql2 -v '0.4.10' succeeds before bundling.
...................
Solution was:
gem update --system
sudo apt-get install libmysqlclient-dev
And then "bundle install" was OK.

Installing mysql2 gem

I have tried installing mysql 2 gem to start building my rails app. I have Rails 4.0.4 and Ruby 1.9.3p545. I've been getting the same error after working on it for several days. I tried installing mysql 32 bit version again to make sure I had the right version with the right connector, moved my libmysql.dll and libmysql.lib to my ruby/bin folder and tried several other means of making it work that I found online. None of them have worked for me. The below is what I have. I would appreciate any help that allows me to finally install the mysql2 gem.
PS C:\Users\pc> gem install mysql2 --no-rdoc --no-ri -- '--with-mysql-lib="C:\Program Files\MySQL\
.6\lib\" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include\"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mys
Program Files\MySQL\MySQL Server 5.6\include"'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb --with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --wit
e=C:\Program Files\MySQL\MySQL Server 5.6\include"
checking for ruby/thread.h... no
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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:/Ruby193/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/lib
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.16 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/mysql2-0.3.16/gem_make.out
We wrote a tutorial on how to do this here
--
There are several issues with what you're doing:
You cannot have any spaces in the paths
You need to include the latest version of MYSQL C-Connector
This works for us:
Download the latest 32 bit version of MYSQL C-Connector
Install into a path without spaces
Use the following command:
gem install mysql2 --platform=ruby -- ‘--with-mysql-dir=”C:\mysql-connector-path”’
This should install it correctly

mysql2 gem failing to install on Windows 7: failed to build gem native extension

we tried suggestions from this SO post about correcting installation errors with the mysql2 gem, but our problems persisted. we also looked at other SO posts like this one, but none helped.
we're on rails 3.2.12 on windows 7.
libmysql.dll is installed in C:\RailsInstaller\Ruby1.9.3\bin, though this was installed in March 2013.
error:
Using mongo_mapper (0.12.0)
Installing mysql2 (0.3.15)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
checking for ruby/thread.h... no
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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/Ruby1.9.3/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}/lib
--with-mysql-config
--without-mysql-config
--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-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15
Results logged to C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.3.15/ext/mysql2/gem_m
An error occurred while installing mysql2 (0.3.15), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.15'` succeeds before bundling.
Wrote an update on how to do this (after we've had to do it a lot):
Download MYSQL C-Connector Library (32-bit only)
Unzip to "no-spaces" path (E.G C:/mysql-connector)
Install the gem using relative paths:
gem install mysql2 —platform=ruby — ‘—with-mysql-dir=”C:\mysql-connector-path”’
Add the DLL to your Ruby/bin folder (you've done already)
Reason
The reason this fails is because Win 7 does not have MYSQL libraries installed, meaning Ruby cannot reference the files it needs to install the gem
You need to install the correct files (which can be removed later on). It seems you've installed the wrong ones, which will probably be the reason why the gem fails to install
Hope this helps!

Error installing mysql2 gem ( windows 8 )

i'm currently trying to install the mysql2 gem on a windows 8 platform. I have installed the mysql_connector and used the following code below. But still seem to be getting the same error. What steps should I take to address this issue.
C:\Users\Samuel>gem install mysql2
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:/Ruby200-x64/bin/ruby.exe extconf.rb
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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:/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-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql
2-0.3.14 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/ext/mysq
l2/gem_make.out
Download the 32-bit Zip Archive of connector from here. Then copy it at the root of your C drive for ease of access so that your connector folder path will be something like this
C:\mysql-connector-c-6.1.3-win32\
Now copy this line of code to your cmd and execute (remember to change the connector version number with your one)
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector-c-6.1.3-win32/"'
After trying for a long time I successfully installed mysql2 gem in both of my 32 and 64 bit windows 7 in this way. Cheers!
I have been using windows 7 and have faced the similar error and ended up in using mysql gem instead of mysql2. And apart from this, many errors kept rising. That made me to shift to linux, and after that no such problems poked me.
I had made a ferocious attempt to include mysql2 fem using windows for a whole day, but the results were not fruitful. If you are really keen to solve, go through these links (link1 and link2). Maybe you will find something useful.
This is how I Installed my mysql2 gem on windows 8.
c:\DevKit>gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Ruby193\my
sql-connector-c-6.1.3-win32/"'

installing mysql gem on rbenv

I'm trying to use vagrant on my MAC OSX machine. I connected vagrant with using SSH and I set ruby 1.9.2-p290. Now I'm try to install ruby gems but I've been facing with this problem when I want to install mysql2 gem.
Fetching: mysql-2.8.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/home/vagrant/.rbenv/versions/1.9.2-p290/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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=/home/vagrant/.rbenv/versions/1.9.2-p290/bin/ruby
--with-mysql-config
--without-mysql-config
--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-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/mysql-2.8.1 for inspection.
Results logged to /home/vagrant/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
I set in Gem file
gem 'mysql2'
and again I run bundle command but the result is the same.
Why doesn't mysql run on vagrant?
The mysql2 gem has native C extensions that build against mysql binaries.
Your vagrant machine needs to have mysql installed.
Do something like this
$ vagrant ssh
$ sudo apt-get install mysql-server mysql-client
After mysql is installed, you should be able to install the mysql2 gem.
EDIT: you also need the mysql development libraries so
$ sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev