ERROR: Failed to create native gem extension (mysql2 on rails 3.2.3)

I am trying to install mysql2 gem with Rails 3.2.3 and it does not work:

β˜… bundle install Fetching gem metadata from https://rubygems.org/......... Using rake (0.9.2.2) Using i18n (0.6.0) Using multi_json (1.2.0) Using activesupport (3.2.3) Using builder (3.0.0) Using activemodel (3.2.3) Using erubis (2.7.0) Using journey (1.0.3) Using rack (1.4.1) Using rack-cache (1.2) Using rack-test (0.6.1) Using hike (1.2.1) Using tilt (1.3.3) Using sprockets (2.1.2) Using actionpack (3.2.3) Using mime-types (1.18) Using polyglot (0.3.3) Using treetop (1.4.10) Using mail (2.4.4) Using actionmailer (3.2.3) Using arel (3.0.2) Using tzinfo (0.3.32) Using activerecord (3.2.3) Using activeresource (3.2.3) Using bundler (1.1.3) Using coffee-script-source (1.2.0) Using execjs (1.3.0) Using coffee-script (2.2.0) Using rack-ssl (1.3.2) Using json (1.6.6) Using rdoc (3.12) Using thor (0.14.6) Using railties (3.2.3) Using coffee-rails (3.2.2) Using jquery-rails (2.0.2) Installing mysql2 (0.3.11) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lmygcc... no checking for mysql_query() in -lmysqlclient... no *** 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 --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/rarneson/.rvm/rubies/ruby-1.9.3-p125/bin/ruby --with-mysql-config --without-mysql-config --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysqlclientlib --without-mysqlclientlib --with-mlib --without-mlib --with-mysqlclientlib --without-mysqlclientlib --with-zlib --without-zlib --with-mysqlclientlib --without-mysqlclientlib --with-socketlib --without-socketlib --with-mysqlclientlib --without-mysqlclientlib --with-nsllib --without-nsllib --with-mysqlclientlib --without-mysqlclientlib --with-mygcclib --without-mygcclib --with-mysqlclientlib --without-mysqlclientlib Gem files will remain installed in /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11 for inspection. Results logged to /Users/rarneson/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/ext/mysql2/gem_make.out An error occured while installing mysql2 (0.3.11), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling. 

I start the installation of the package, and this is in my Gemfile:

 gem 'mysql2', '~> 0.3.11' 

MySQL is currently running through MAMP. I'm not sure if this is a bad idea, and I have to run vanilla MySQl, but it seems my current problem is just to set the stone. I saw a lot of such problems here in stackoverflow, but they all are slightly different or have really complex solutions. Is there something I'm missing? Something simple? Is something stupid? If necessary, I can provide additional information from an external file. I read that some people use SQLite for developers and test MySQL in prod, but that sounds like a pretty terrible idea.

+46
mysql ruby-on-rails mysql2
Apr 7 '12 at 3:19
source share
7 answers

In the end, I just installed a new copy of MySQL and did not use MAMP, and this did the trick. It was also necessary to install a 64-bit version, not a 32-bit one.

+1
May 15 '12 at 2:14
source share
β€” -

From https://github.com/brianmario/mysql2/issues/8

just copied it in the console

 sudo apt-get install mysql-client libmysqlclient-dev 

and working!

+127
Jul 24 '12 at 0:00
source share

I used Homebrew for Mac to install mysql:

 brew install mysql 

Then I used the gem command to install mysql2 gem:

 sudo gem install mysql2 
+40
Oct 28
source share

This is mainly due to the lack of mysql headers, try installing mysql developer packages (mysql-devel)

This error usually occurs when the libmysqlclient-dev package is missing.

+17
Apr 7 2018-12-12T00:
source share

I ran into the same problem using OS X Sierra and MAMP and Rails 5. I successfully installed gem through

 gem install mysql2 -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config 

After that, the batch installation worked fine.

+2
May 8 '17 at 12:03
source share

You can follow this topic of Errors Installing mysql2 gem through the Bundler , which explains the solution for Centos, and this problem will be fixed if you configure the commands on your OS and you can successfully install the mysql2 gem.

0
Aug 22 '12 at 6:19 06:19
source share

Just add MAMP mysql to your PATH, then you can start the installation of the package as normal.

$ / Applications / MAMP / Library / bin / mysql --host = localhost -uroot -proot

source: http://blog-en.mamp.info/2009/08/using-mysql-command-line-with-mamp.html

0
Oct 29 '13 at 13:03 on
source share



All Articles