Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Migrations and Relationships Migrations

AIA Developers
AIA Developers
9,806 Points

Mysql Error

Hi There I am getting following error whenI am trying to create new project using mysql

Mysql is install correctly and I can get to mysql by typing "mysql"

Please help

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/Users/khurram.shahzad/.rbenv/versions/2.0.0-p353/bin/ruby 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

Using mysql_config at /Applications/MAMP/Library/bin/mysql_config

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/khurram.shahzad/.rbenv/versions/2.0.0-p353/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

Gem files will remain installed in /Users/khurram.shahzad/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/mysql2-0.3.18 for inspection. Results logged to /Users/khurram.shahzad/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/mysql2-0.3.18/ext/mysql2/gem_make.out An error occurred while installing mysql2 (0.3.18), and Bundler cannot continue. Make sure that gem install mysql2 -v '0.3.18' succeeds before bundling.

3 Answers

Sage Elliott
Sage Elliott
30,003 Points

I had the same problem before, I added "export PATH=${PATH}:/usr/local/mysql/bin" to my .bash_profile as this stack overflow suggested. You can also run that first in your terminal to make sure it fixes your error before editing your bash profile!

http://stackoverflow.com/questions/10577374/mysql-command-not-found

Here's a blog post explaining how to configure mySQL with Rails: http://paul-wong-jr.blogspot.mx/2011/06/getting-mysql2-gem-to-work-with-ruby-on.html

Also as you said you already have installed mySQL in your OS, you can try installing the gem while passing the path in where you have mysql installed:

gem install mysql2  --with-mysql-dir=c:/mysql-connector-c-x-y-z

The gem readme also recommends you to install the DevKit compiler with your Ruby installation, you can download it here: http://rubyinstaller.org/downloads/

Hope this helps!