2011-02-17 110 views
3
寶石mysql2
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 

編輯問題與Rails3中在Mac上安裝

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 

,做什麼ü建議後...

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

這裏是錯誤..

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 ..

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

即使無法連接到mysql。

Check this screenshot

EDIT5

這是解決方案,但我無法理解,爲什麼MySQL服務器沒有啓動..

Screenshot

+0

看起來你缺少ruby開發包。或者,您可以嘗試http://bitnami.org/stack/rubystack – Zimbabao 2011-02-17 09:50:23

+0

我強烈建議您使用RVM和mysql與自制軟件安裝ruby。這很簡單,這是有效的。 – apneadiving 2011-02-19 23:54:29

回答

6

嘗試以下,這似乎有worked for others

  1. 從終端,運行locate mysql_config並確定路徑在mysql_config二進制
  2. 使用該路徑在下面的命令來安裝寶石:sudo gem install mysql2 -- –with-mysql-config=/path/you/identified/above/mysql_config

[編輯]

在應對新的錯誤,例如:

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 

我相信這是由於mysql2沒有使用libmysqlclient.16.dylib的完整路徑。其他曾與運氣:

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 

但是,一定要更換/usr/local/mysql/lib/libmysqlclient.16.dylib與路徑自己libmysqlclient.16.dylib。我不積極會怎麼做,但你可以用locate找到它(如果沒有,請在lib目錄查看/usr/local/mysql-5.5.9-osx10.6-x86_64)。從這裏再

0

嘗試從MacPorts的

sudo ports install mysql5 

它經歷了千百年來安裝MySQL完成,但一旦完成運行

gem install mysql2 

和一切都應該工作得很好