Last Updated: February 25, 2016
·
9.078K
· dfang

gem install mysql2 failed on mac, mysql.h is missing ....

$ > gem install mysql2                                                                                                                                                                             

Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/dfang/.rbenv/versions/1.9.3-p392/bin/ruby extconf.rb
checking for rbthreadblockingregion()... yes
checking for rb
waitforsinglefd()... yes
checking for rb
hashdup()... yes
checking for rb
intern3()... 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=/Users/dfang/.rbenv/versions/1.9.3-p392/bin/ruby
--with-mysql-config
--without-mysql-config

Gem files will remain installed in /Users/dfang/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13 for inspection.
Results logged to /Users/dfang/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13/ext/mysql2/gem_make.out

there are duplicate questions in google, but not works

1.http://stackoverflow.com/questions/3754662/errors-installing-mysql2-gem-via-the-bundler

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

3.http://stackoverflow.com/questions/11119482/getting-error-mysql-h-is-missing-while-bundle-install-ror

4.http://stackoverflow.com/questions/17238226/mysql2-gem-fails-to-compile-with-mysql-5-6-12-on-os-x-with-homebrew

5.https://coderwall.com/p/whbzrw

the solution works for me is :

gem install mysql2 --with-mysql-config=/usr/local/Cellar/mysql/5.6.12/bin/mysql_config

replace 5.6.12 to your version
you can dig into mysql cellar directory to find you version number

brew --cellar mysql

Hope it helps

3 Responses
Add your response

You are a saint. After 3 hours of searching, your solution worked. Thank you for sharing.

I had this extremely perplexing error:
errmsg.h is missing. please check your installation of mysql and try again.

over 1 year ago ·

I love you. Please fix the magic command, -- (double dash) missing after «...mysql2». This right: gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.12/bin/mysql_config

over 1 year ago ·

Bless you! After adding the '--' after 'mysql2' (not to mention, after an hour of digging through 100 other forum posts) this finally solved my problem.

over 1 year ago ·