Errors Installing gem mysql2 through the bundler

I am trying to install mysql2 stone through the Bundler, but it continues to die with the following error:

 ** executing command /home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError) /home/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb --with-mysql-config=/usr/bin/mysql_config checking for rb_thread_blocking_region()... yes checking for mysql.h... no checking for mysql/mysql.h... no ----- mysql.h is missing. please check your installation of mysql and try again. ----- *** 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/cc_rails/.rvm/rubies/ruby-1.9.2-p0/bin/ruby --with-mysql-config Gem files will remain installed for inspection. 

Most of the things I found through Googling recommend passing the --with-mysql-config parameter to fix this. So based on:

 $ which mysql_config /usr/bin/mysql_config 

I added the following to the Bundler configuration:

 $ bundle config build.mysql2 --with-mysql-config='/usr/bin/mysql_config' 

However, luck is not yet - the same mistake as above.

Since it is dying with the error mysql.h is missing , I checked this and it is supposedly around, the Bundler simply could not be found.

 $ find / -name mysql.h /usr/include/mysql5/mysql/mysql.h 

Any thoughts?

+60
ruby mysql ruby-on-rails rubygems bundler
Sep 20 '10 at 19:10
source share
8 answers

The answer was similar to the one posted by Wrikken - this is what I did to fix it for the sake of future readers.

(This is for RHEL 5.5 - the same but different commands are used for Ubuntu / Debian / etc.)

Running sudo yum list installed print all installed packages on your computer (note: yum on RHEL needs to add the Red Hat Network repository [I use EPEL ] and run it through sudo ).

I had mysql and mysql-server which explained why MySQL worked fine for every existing application, but not mysql-devel , which is necessary to fix mysql.h is missing error and similar other build errors.

In short, after mysqldump -u root -ppassword --all-databases > full-dump.sql for security, it was fixed with a simple

 sudo yum install mysql-devel 
+95
Sep 21 '10 at 13:58 on
source share

For Ubuntu, you need to install the following. libmysqlclient-dev libmysqlclient16

+33
Oct 10 2018-10-10
source share

For Mac with mysql brew installation, the following solution fixed the problem for me:

I edited the mysql_config file in / usr / local / Cellar / mysql / 5.6.12 / bin and removed the W compiler options -Wno-null-conversion and -Wno-unused-private-field for cflags and cxxflags.

This solved the problem with "gem install mysql2".

Link: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

+20
Jun 23 '13 at 11:57
source share

The above problem will occur because the mysql-devel package is not installed correctly on your system. I will explain the same thing in Centos how to fix it. When you try to install this package,

  yum install mysql-devel 

Sometimes there will be some collision with existing packages that are installed if you install the MySql-Administrative tool and the MySQL query browser.

In this case, you need to uninstall all existing mysql2 packages and install it again.

  rpm -qa -last | grep -i mysql yum remove MySQL-server-5.5.27-1.rhel5 yum remove MySQL-client-5.5.27-1.rhel5 yum remove mysql-gui-tools-5.0r12-1rhel4 yum remove mysql-query-browser-5.0r12-1rhel4-a 

So, you can remove all mysql objects displayed with rpm -qa as above.

Then you can install the mysql server and mysql client.

  yum install mysql-server yum install mysql-client 

You are now installing the mysql-devel package.

  yum install mysql-devel 

Now there are no package collisions, and you can install the mysql2 gem.

  gem install mysql2 -v '0.3.11' 

Now your mysql2 game will be successfully installed and you will go well.

+8
Aug 22 '12 at 6:13
source share

In my case, the problem was the wrong mysql_config script. When you call the command line with the -cflags parameter, a string of parameters containing:

  -Xclang -target-feature -Xclang -aes -Qunused-arguments 

For some reason, calling to_header ('mysql.h') in the extconf.rb script file will fail if this option is enabled.

What worked for me was to manually edit the mysql_config file, removing the link to these options from the line:

  cflags = "- I $ pkgincludedir -Os -w -pipe -march = native -Xclang -target-feature -Xclang -aes -Qunused-arguments -O2 -g -DDBUG_OFF" #note: end space! 

which I rewrote as:

  cflags = "- I $ pkgincludedir -Os -w -pipe -march = native -O2 -g -DDBUG_OFF" #note: end space! 
+1
Jun 03 '13 at 20:48
source share

I got the same error. and for ubuntu 16. I had to write the command below:

 sudo apt-get install libmysqlclient-dev 

and it works.

+1
Mar 30 '17 at 10:30
source share

I know this is ancient, but if someone else gets this zlib error, make sure you type: Using rvm

(any version you use)

I could swear I did it. Just posting in case someone pulls their hair out and that helps. If not good luck. :)

0
Mar 28 '12 at 23:55
source share

I ran into this problem when installing the package for redmine on Fedora 23. The solution I found was to issue this command - sudo dnf install redhat-rpm-config .

Not only fix my problem with installing mysql2, but also for nokogiri and redcarpet.

0
Apr 02 '16 at 7:41
source share



All Articles