16

I've followed the instructions on http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/ , including the installation of ruby via macport.

Whenever I execute gem install mysql , I'll get the following error

bash-3.2# gem install mysql
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

        /opt/local/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... 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=/opt/local/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

How can I resolve this issue ? I've installed the 32-bit mysql using the package file (.pkg) and also, I'm extremely new to ruby...

Update 4/26/11 5:11pm EST Installed RVM and updated ruby to 1.9.2 Also I have looked through the links posted on the comments. I did locate mysql_config and results were

/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config
/usr/local/mysql-5.1.56-osx10.6-x86/man/man1/mysql_config.1

Hence, I tried gem install mysql - -with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config but it still doesn't work... I did get new error information however..

/Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:440:in `try_link'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:552:in `try_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:797:in `block in have_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:796:in `have_func'
    from extconf.rb:50:in `<main>'


Gem files will remain installed in /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/bin/th-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config/gems/mysql-2.8.1 for inspection.

Really wish to thank those who commented... and really appreciate if more help can be given..... been trying to get the darn mysql installed for 2 days...

Kyle
  • 915
  • 8
  • 18
  • 34
  • "Check the mkmf.log file for more details." - Can you provide the parts which look "interesting" from there? It's hard to guess without an actual error message. – johannes Apr 26 '11 at 19:18
  • where can I find the mkmf.log file ? Sorry... extremely new here.. – Kyle Apr 26 '11 at 19:20
  • 3
    http://stackoverflow.com/questions/1857059/cant-install-do-mysql-gem, http://stackoverflow.com/questions/2167598/mysql-install-error-failed-to-build-gem-native-extension, http://stackoverflow.com/questions/2716527/how-to-install-mysql-gem-on-mac-os-10-6 – fl00r Apr 26 '11 at 19:43
  • 3
    Try `sudo apt-get install libmysqlclient-dev libmysqlclient16` and then `gem install mysql2`. – Zabba Apr 26 '11 at 21:20
  • @Zabba, you should post that as an answer. – Koen. Oct 29 '12 at 12:29

9 Answers9

22

The program 'mysql_config' is currently not installed. You can install it by typing:

$ sudo apt-get install libmysqlclient-dev
$ bundle install

bundle show [mysql2] # To find the location.
Raul Rene
  • 10,014
  • 9
  • 53
  • 75
Vicky
  • 419
  • 5
  • 10
11

Try this:

gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config

(Note the extra dashes)

If that doesn't work, I highly recommend going with the homebrew installation mentioned above of MySQL. You can read about a soup-to-nuts installation here: Uninstall Ruby on Rails on Mac OS X 10.6

Community
  • 1
  • 1
Mike Farmer
  • 2,992
  • 4
  • 28
  • 32
  • 3
    a tip for mac users: use finder and do 'go to folder' to find your mysql installation. once you've found the config file, drag the mysql_config icon from finder into terminal to have the path in your terminal window – Danny Nov 21 '11 at 17:41
  • 2
    For homebrew 0.9.4 path is `/usr/local/Cellar/mysql//bin`, but it still isn't working for me... – James McMahon Jun 28 '13 at 20:49
  • I AGREE GOLD! also for rails I added: `bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql55/5.5.49/bin/mysql_config` – Andrew Arrow Oct 24 '16 at 15:13
9

I had the same issue in Cent OS, but got it resolved by installing mysql-devel

 yum install mysql mysql-server mysql-devel
tk120404
  • 2,985
  • 1
  • 27
  • 28
5

Based on this answer I ended up editing my /usr/local/Cellar/mysql/5.6.12/bin/mysql_config file to remove -Wno-null-conversion -Wno-unused-private-field, which is what the error the mkmf.log was complaining about.

My setup is Mac OSX with Ruby installed using RVM and MySQL installed using homebrew.

Community
  • 1
  • 1
James McMahon
  • 48,506
  • 64
  • 207
  • 283
4

If you are using bundler you can set build parameters for your gems by using bundle config, this will save your build options to ~/.bundle/config, so that the next time you need to build your gem, the configuration options will already be set, eg:

bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

bundle config man page

knowuh
  • 341
  • 4
  • 4
4

Solved the problem by uninstalling 32-bit MySQL thats on my system.. and installed 5.1.56 64-bit.

Hope this is helpful to others who's having the same problem as me..

Kyle
  • 915
  • 8
  • 18
  • 34
2

For mac as of November 2018

gem install mysql2 -v '0.4.8' -- --with-ldflags=-L/usr/local/opt/mysql@5.7/lib --with-cppflags=-I/usr/local/opt/mysql@5.7/include

In case you still have issues, try the following before installing the gem

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
abmap
  • 141
  • 5
1

If you are willing, you can try a completely different approach using homebrew to install mysql:

https://github.com/mxcl/homebrew

And then try installing the gem based on that.

Chris Cherry
  • 28,118
  • 6
  • 68
  • 71
  • 1
    I have installed homebrew. Could you go about showing me how to install mysql gem with that ? I'm reading the wiki on Gems, Eggs and Perl Modules. It doesn't explain much tho... – Kyle Apr 27 '11 at 13:41
0

Following below steps

  1. sudo apt-get update
  2. sudo apt-get install mysql-client libmysqlclient-dev
  3. gem install mysql2