使用Mac OS X和mysql2的Rails - LoadError:找不到dlsym符号

时间:2012-10-10 10:55:37

标签: mysql ruby macos

我从官方网站安装了mysql 5.1.61。它已被编译和安装,但现在当我尝试运行简单的rake db:migrate时,它显示了这样的错误

Connecting to {:password=>nil, :encoding=>"utf8", :database=>"mnemosyne_spec", :host=>"localhost", :username=>"root", :adapter=>"mysql2"}
rake aborted!
LoadError: dlsym(0x7faaf9048bf0, Init_mysql2): symbol not found - /Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

Tasks: TOP => db:migrate

完整追踪:

** Invoke db:migrate (first_time)
** Execute db:migrate
Connecting to {:password=>nil, :encoding=>"utf8", :database=>"mnemosyne_spec", :host=>"localhost", :username=>"root", :adapter=>"mysql2"}
rake aborted!
LoadError: dlsym(0x7fafa1d30510, Init_mysql2): symbol not found - /Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/mysql2-0.3.11/lib/mysql2.rb:9
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/adapters/mysql2.rb:1:in `require'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/adapters/mysql2.rb:1
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:379:in `k_require'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:379:in `tsk_require'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:100:in `check_requiring_thread'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:97:in `synchronize'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:97:in `check_requiring_thread'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:379:in `tsk_require'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/database/connecting.rb:25:in `adapter_class'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/database/connecting.rb:67:in `connect'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/gems/sequel-3.39.0/lib/sequel/core.rb:147:in `connect'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/lib/mnemosyne.rb:52:in `db_connect!'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/lib/mnemosyne.rb:32:in `configure'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/lib/mnemosyne.rb:25:in `initialize!'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/lib/mnemosyne/database_tasks.rb:21:in `initialize'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/lib/mnemosyne/database_tasks.rb:83:in `initialize'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/Rakefile:63:in `new'
/Users/serg/rails_projects_terminal/brandspotter/mnemosyne/Rakefile:63
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/Users/serg/.rvm/rubies/ruby-1.8.7-p370/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/gems/rake-0.9.2.2/bin/rake:33
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/bin/rake:19:in `load'
/Users/serg/.rvm/gems/ruby-1.8.7-p370@global/bin/rake:19
/Users/serg/.rvm/gems/ruby-1.8.7-p370@mnemosyne/bin/ruby_noexec_wrapper:14
Tasks: TOP => db:migrate

我试图重新安装红宝石和宝石,它什么都没改变。我该怎么做才能解决这个问题?

我的信息:

Mac OS X 10.8.2 Mountain Lion
Xcode 4.5.1
osx-gcc-installer
Mysql  Ver 14.14 Distrib 5.1.61, for apple-darwin10.3.0 (i386) using readline 5.1
RVM 1.16.10

P.S。我从自制软件安装mysql时没有遇到这样的问题。

1 个答案:

答案 0 :(得分:0)

我创立了解决方案!

问题出在MySQL安装中。它是x86,对于Mac OS X 10.7 +不正确。

1)所以,首先我们应该删除旧版本的MySQL:

$ sudo rm /usr/local/mysql
$ sudo rm -rf /usr/local/mysql*
$ sudo rm -rf /Library/StartupItems/MySQLCOM
$ sudo rm -rf /Library/PreferencePanes/My*
$ sudo rm -rf /Library/Receipts/mysql*
$ sudo rm -rf /Library/Receipts/MySQL*
$ sudo rm -rf /var/db/receipts/com.mysql.*

1.1)运行之后

$ nano /etc/hostconfig

并删除

MYSQLCOM=-YES-

2)为了确保一切顺利,你至少可以删除mysql gem:

$ gem uninstall mysql2

或者您可以通过rvm删除gemset中的所有宝石:

$ rvm gemset empty your-gemset-name

3)然后安装 x64 MySQL版本

4)并通过bundler安装所有缺少的宝石:

$ bundle