Last Updated: February 25, 2016
· 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:

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






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 ·