Ruby on Rails服务器无法启动:dyld:惰性符号绑定失败:未找到符号:_mysql_get_client_info

时间:2011-12-23 04:27:41

标签: mysql ruby-on-rails ruby osx-lion

环境(Mac OS X 10.7.2 - Lion):

$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10]
$ rails -v
Rails 3.1.3
$ mysql -v
Server version: 5.1.44 

我尝试运行以下内容,但每次即使应用了来自网络的修补程序后,我也会遇到同样的错误:

$ rails server

dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
Referenced from: /Users/pressplay/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace

dyld: Symbol not found: _mysql_get_client_info
Referenced from: /Users/pressplay/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace

Trace/BPT trap: 5

修复尝试失败包括:

sudo install_name_tool -change libmysqlclient.16.dylib /Applications/MAMP/Library/lib/mysql/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.3-p0/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

sudo ln -s /Applications/MAMP/Library/lib/mysql/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

3 个答案:

答案 0 :(得分:7)

如果您使用的是rvm / without rvm(只需使用sudo),请使用以下命令解决问题。

rvmsudo ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config --with-opt-lib=/usr/local/mysql/lib 

答案 1 :(得分:2)

卸载mysql2 gem然后用sudo安装gem解决了它。

gem uninstall mysql2
sudo gem install mysql2

答案 2 :(得分:0)

我可以补充一点,首先需要卸载mysql2 gem,然后按照上面的说明重新安装。

sudo gem uninstall mysql2