3
 Installing mysql2 (0.2.6) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework  /Versions/1.8/usr/lib/ruby/ruby.h


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6 for inspection.  
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/ext/mysql2/gem_make.out
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `each'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:446:in `build_extensions'
from /Library/Ruby/Site/1.8/rubygems/installer.rb:198:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/source.rb:96:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:55:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/spec_set.rb:12:in `each'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:44:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/installer.rb:8:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/cli.rb:226:in `install'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `send'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/task.rb:22:in `run'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor.rb:246:in `dispatch'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/vendor/thor/base.rb:389:in `start'
from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

EDIT

  Mohit-Jains-MacBook-Pro:casecreed mohit$ locate mysql_config
 /Applications/XAMPP/xamppfiles/bin/mysql_config
 /usr/local/mysql-5.5.9-osx10.6-x86_64/bin/mysql_config
 /usr/local/mysql-5.5.9-osx10.6-x86_64/man/man1/mysql_config.1

and after doing what u suggested...

ie

     sudo gem install mysql2 -- –with-mysql-config=/usr/local/mysql-5.5.9-osx10.6-x86_64/bin/mysql_config

here is the error..

    Mohit-Jains-MacBook-Pro:casecreed mohit$ rake db:create
    (in /Users/mohit/projects/casecreed)
    rake aborted!
    dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
      Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
      Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
    /Users/mohit/projects/casecreed/Rakefile:4
    (See full trace by running task with --trace

EDIT2

screenshot of whole process after answer was modified..

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql2", "database"=>"the_casecreed_test", "host"=>"localhost", "pool"=>5, "password"=>nil}, charset: utf8, collation: utf8_unicode_ci
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql2", "database"=>"the_casecreed_development", "host"=>"localhost", "pool"=>5, "password"=>nil}, charset: utf8, collation: utf8_unicode_ci

EDIT3

development.yml

EDIT4

Even not able to connect to mysql.

Check this screenshot.

EDIT5

This is the solution but i am not able to understand, why mysql server was not starting..

Screenshot

Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
  • Looks like you are missing ruby development package. Alternatively you can try http://bitnami.org/stack/rubystack – Zimbabao Feb 17 '11 at 09:50
  • I highly recommend you install ruby with RVM and mysql with homebrew. This is simple, this works. – apneadiving Feb 19 '11 at 23:54
  • @apneadiving whats the need for that? i just want to instal mysql2 gem thats it. Its working perfecltly on my linux machine. just bought a macbook pro and not able to install on it.. – Mohit Jain Feb 19 '11 at 23:59

3 Answers3

6

Try the following, which seems to have worked for others:

  1. From the Terminal, run locate mysql_config and identify the path to the mysql_config binary
  2. Use that path in the following command to install the gem:sudo gem install mysql2 -- –with-mysql-config=/path/you/identified/above/mysql_config

[Edit]

In response to the new error, e.g.:

Mohit-Jains-MacBook-Pro:casecreed mohit$ rake db:create
(in /Users/mohit/projects/casecreed)
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
/Users/mohit/projects/casecreed/Rakefile:4
(See full trace by running task with --trace

I believe this is due to mysql2 not using the full path to libmysqlclient.16.dylib. Others have had luck with:

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

However, be sure to replace /usr/local/mysql/lib/libmysqlclient.16.dylib with the path to your own libmysqlclient.16.dylib. I'm not positive what it would be, but you may be able to find it with locate (if not, check around in the lib directory for /usr/local/mysql-5.5.9-osx10.6-x86_64).

Community
  • 1
  • 1
Michelle Tilley
  • 157,729
  • 40
  • 374
  • 311
  • @Brandon Tilley cool.. we are seems quit clone.. can u check the edit2 part.. added a screenshot..Thanks a lot man... – Mohit Jain Feb 20 '11 at 09:18
  • That's interesting; I know this sounds silly, but can you double check your `config/database.yml` to make sure there's no "socket" entry in your `development` section? – Michelle Tilley Feb 20 '11 at 09:50
  • @Brandon Tilley ya there is nothing like that... check edit3. Uff.. I think i made a mistake by buyin this mac.. Ubuntu is so good.. I thnk i should move back and throw this bloody machine.. – Mohit Jain Feb 20 '11 at 10:06
  • @Brandon Tilley check edit3 and edit4.. i am not able to connect to mysql using command line. – Mohit Jain Feb 20 '11 at 11:01
  • @Brandon Tilley something worked, Please check edit5. Can u help me whats happening. and why? – Mohit Jain Feb 20 '11 at 16:18
  • I think that MySQL is starting by default using a command that's placing a connect socket somewhere else on the system. Do a fresh restart (or however you need to reset the system to a "default" MySQL state) and run `ps aux | grep mysql` and see if you see a mysqld line with the `--socket` option on it. If you do, you can either modify `database.yml` to point to it (`socket: /path/to/real/mysqld.sock`) or you can create a symlink to it in `/tmp/mysql.sock`. When you ran mysqld_safe it ran w/o socket opt. Don't give up! Although I have to say I never had this much trouble w/ MySQL on my Mac :) – Michelle Tilley Feb 20 '11 at 18:20
  • 1
    "I think i made a mistake by buyin this mac.. Ubuntu is so good.. I thnk i should move back and throw this bloody machine." ... or at least give it back to Mohit Jain ;-P – jemminger Feb 20 '11 at 22:03
  • @brandon perfect. thanks ur help plus google.com solved the things.. thanks a lot.. – Mohit Jain Feb 22 '11 at 05:32
3

download 64 bit from here and then try to install mysql2 gem

http://dev.mysql.com/downloads/mysql/

it will work..

user626035
  • 191
  • 4
0

Try installing mysql from macports

sudo ports install mysql5

It took ages to complete, but once done run

gem install mysql2

and everything should work just fine

Edwin
  • 3,812
  • 2
  • 21
  • 16