我一直遇到MySQL服务器安装问题,在停电后搞砸了。
Intel i5 Mac运行OS X 10.6.5
Ruby 1.9.2安装
安装Rails 3.0.1
MySQL服务器(最后)安装并运行
我完全重新安装了MySQL,它删除了本地开发/测试/生产数据库。所以,我在MySQL中运行create database development;
以使dev数据库准备好进行迁移。
rake db:migrate
以重新获取我的数据库。 (我目前无法从Rails访问我的数据库或Mysql。)使用gem 'mysql', '2.8.1'
并运行rake db:migrate
,我收到错误:
rake aborted!
undefined method 'init' for Mysql:Class
堆栈追踪:
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/mysql_adapter.rb:30:in 'mysql_connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in 'new_connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in 'checkout_new_connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in 'block (2 levels) in checkout'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in 'loop'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in 'block in checkout'
/Users/sscirrus/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in 'mon_synchronize'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in 'checkout'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in 'connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in 'retrieve_connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in 'retrieve_connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in 'connection'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/migration.rb:486:in 'initialize'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in 'new'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/migration.rb:433:in 'up'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/migration.rb:415:in 'migrate'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/railties/databases.rake:142:in 'block (2 levels) in <top (required)>'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in 'call'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in 'block in execute'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in 'each'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in 'execute'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in 'block in invoke_with_call_chain'
/Users/sscirrus/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in 'mon_synchronize'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in 'invoke_with_call_chain'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:in 'invoke'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in 'invoke_task'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in 'block (2 levels) in top_level'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in 'each'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in 'block in top_level'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:in 'top_level'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in 'block in run'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in 'standard_exception_handling'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in 'run'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in '<top (required)>'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in 'load'
/Users/sscirrus/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in '<main>'
答案 0 :(得分:4)
我有Rails 3.1-rc4,MySQL 5.5.15(刚升级)和Mac OS X Lion。我的问题原来是mysql_api.bundle文件链接到正确的libmysqlclient.18.dylib文件,但它找不到库:
otool -L ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql-2.8.1/lib/mysql_api.bundle
/Users/rowland/.rvm/gems/ruby-1.9.2-p180/gems/mysql-2.8.1/lib/mysql_api.bundle:
/Users/rowland/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.1.9.1.dylib (compatibility version 1.9.1, current version 1.9.1)
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
在运行时,找不到库。我第一次尝试解决这个问题是添加一个LC_RPATH命令,但这还不够(也许是因为它在列表的末尾)。相反,我直接用以下方式更改了库链接:
install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180\@rails-3.1/gems/mysql-2.8.1/lib/mysql_api.bundle
现在otool告诉我:
otool -L ~/.rvm/gems/ruby-1.9.2-p180\@rails-3.1/gems/mysql-2.8.1/lib/mysql_api.bundle
/Users/rowland/.rvm/gems/ruby-1.9.2-p180@rails-3.1/gems/mysql-2.8.1/lib/mysql_api.bundle:
/Users/rowland/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.1.9.1.dylib (compatibility version 1.9.1, current version 1.9.1)
/usr/local/mysql/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
再次开心。这仅适用于Mac OS X.
答案 1 :(得分:3)
你正在寻找的是正确here。
Oluf Nielsen
答案 2 :(得分:2)
这一行帮助我摆脱了上面的错误。在Mac OS X 10.7上。狮子
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH" >> ~/.profile
答案 3 :(得分:1)
没有其他解决方案适合我,但是:
brew install mysql-connector-c
sudo gem install mysql -- --with-mysql-lib=/usr/local/mysql/lib
答案 4 :(得分:1)
我遇到了同样的错误,尝试使用mysql-2.8.1 gem在CentOS上运行一个rails网站。如果我以root身份启动它,我可以运行该网站,但是当我切换到我的应用程序用户时,它会抛出此错误。它最终成为mysql目录结构的权限。我在mysql目录上运行chmod -R 755
并重启了我的rails服务器,错误就消失了。该错误有点模糊,似乎涵盖了驱动程序连接到数据库时的所有内容。
答案 5 :(得分:0)
这对我在ubuntu上起作用
export LD_LIBRARY_PATH=/usr/local/mysql/lib
ldconfig
我只是把它放在/etc/profile
的底部,对于任何新的登录,事情都可以正常工作。您可以快速测试它而无需再次登录
source /etc/profile
答案 6 :(得分:0)
添加Shaun的答案,我可以使用:
我的设置是通过Homebrew安装OS X Lion + apache + passenger + mysql。当我运行“rails server”时,我必须设置一个DYLD_LIBRARY_PATH变量,但我无法弄清楚如何在apache中设置它。我不得不这样做:
cd /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib
sudo install_name_tool -change libmysqlclient.18.dylib `brew --prefix mysql`/lib/libmysqlclient_r.18.dylib mysql_api.bundle
同样的答案,仅限于Homebrew安装,我的宝石不在他/她的〜/ .rvm / gems中。
答案 7 :(得分:0)
我得到同样的错误,但我已经将'mysql'中的gem替换为'mysql2',并且它适用于我 所以,如果任何人仍然得到相同的错误,我与你分享