2015-01-26 84 views
1

我是PHP開發者,我使用XAMPP。我決定現在就深入Ruby,並且我想從XAMPP for Ruby中使用MySQL安裝,並且遇到了讓Gem for mysql正確安裝的問題。RoR + XAMPP + MySQL - Gem安裝MySQL問題

我執行的命令是這樣的:

sudo gem install mysql -- —–with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config 

,我得到的錯誤是這樣的:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. 

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150126-99463-2b5bwp.rb extconf.rb 
checking for mysql_ssl_set()... no 
checking for rb_str_set_len()... yes 
checking for rb_thread_start_timer()... no 
checking for mysql.h... yes 
clang: warning: argument unused during compilation: '-L/Applications/XAMPP/xamppfiles/lib' 
creating Makefile 

make "DESTDIR=" clean 

make "DESTDIR=" 
compiling mysql.c 
clang: warning: argument unused during compilation: '-L/Applications/XAMPP/xamppfiles/lib' 
linking shared-object mysql/mysql_api.bundle 
ld: library not found for -lmysqlclient 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [mysql_api.bundle] Error 1 

make failed, exit code 2 

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/mysql-2.9.1 for inspection. 
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/mysql-2.9.1/gem_make.out 
An error occurred while installing mysql (2.9.1), and Bundler cannot continue. 
Make sure that `gem install mysql -v '2.9.1'` succeeds before bundling. 

如果我做了locate mysql_config,我得到這個:

/Applications/XAMPP/xamppfiles/bin/mysql_config 
/Applications/XAMPP/xamppfiles/bin/mysql_config_editor 
/Applications/XAMPP/xamppfiles/man/man1/mysql_config.1 
/Applications/XAMPP/xamppfiles/man/man1/mysql_config_editor.1 

我已經完成了所有關於SO的幫助請求,並且我無法找到解決特定問題的解決方案。

任何幫助,將不勝感激。如果您需要更多信息,請告訴我。

謝謝!

+0

嘗試使用mysql2而不是mysql。 這裏有一些說明http://stackoverflow.com/questions/17758945/cant-install-mysql2-on-mac-os-10-9 – 2015-01-26 20:04:56

回答

0

我注意到OP安裝了XAMMP。這是我在安裝XAMPP之後必須做的工作。我警告你,這是不優雅,但它確實讓你避免

# first, fake the location of the headers 
sudo ln -s /Applications/XAMPP/xamppfiles /usr/local/mysql 
# second, let the libraries etc show up where they are expected: 
cd /usr/local/mysql/lib/mysql 
for i in ../libmysql*; do sudo ln -s $i .; done 
# and finally, one last hack for dynamic loading to work 
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib 

我警告你,這是一個有點難看:-)

0

這爲我工作在Mac OS的MySQL安裝第二X海伊謝拉使用的RubyGems:

gem install mysql2 -- \ 
     --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config \ 
     --with-mysql-dir=/Applications/XAMPP/xamppfiles/mysql/ \ 
     --with-mysql-lib=/Applications/XAMPP/xamppfiles/lib/mysql/ \ 
     --with-mysql-include=/Applications/XAMPP/xamppfiles/include/ \ 
     --no-ri --no-rdoc 
1

我想通了這一點:

bundle config build.mysql --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config 
gem install mysql2 

我的客戶:

require 'mysql2' 
client = Mysql2::Client.new(:host => "127.0.0.1", :username => "root")