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 rbwaitforsinglefd()... yes
checking for rbhashdup()... yes
checking for rbintern3()... 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
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
Written by fang
Related protips
3 Responses
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.
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
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.