mysql 似乎不适用于我的新 Rails 应用程序

标签 mysql ruby-on-rails-3 sqlite installation

我似乎根本无法让 mysql 与我的新 Rails 应用程序一起工作...下面的终端副本:

Janes-MacBook-Pro:development janelee$ cd hellomysql
Janes-MacBook-Pro:hellomysql janelee$ rails server
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found.  Did find: (LoadError)
    /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2.rb:9
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `require'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler.rb:122:in `require'
    from /Users/janelee/Development/hellomysql/config/application.rb:7
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50
    from script/rails:6:in `require'
    from script/rails:6
Janes-MacBook-Pro:hellomysql janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found.  Did find:
    /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

(See full trace by running task with --trace)

我也试过这个:

Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3

You have requested to uninstall the gem:
    sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_32" sudo gem install sqlite3
Password:
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found.  Did find:
    /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle

(See full trace by running task with --trace)

还有这个:

Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3

You have requested to uninstall the gem:
    sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_64" sudo gem install sqlite3
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found.  Did find:
    /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle

(See full trace by running task with --trace)

在重新安装 Lion 之前我还应该尝试什么?

最佳答案

研究使用 Ruby 版本管理器(称为 rvm),然后更新 Ruby。尝试使用 1.9 版或更高版本的 ruby​​。不要重新安装操作系统。如果有的话,移除导轨,移除 ruby 。安装 rvm,安装 ruby​​ 1.9,安装 rails。如果你遵循那个食谱,一切都会好起来的。

配置 Rails 以与 MySQL 一起工作将通过更改文件来实现:

myappname/config/database.yml  

好资料在这里:How do I set MySQL as the default database in Rails 3?

... 在这里:Create a new Ruby on Rails application using MySQL instead of SQLite

习惯于查看 Rails 指南。像这样的例子:http://guides.rubyonrails.org/getting_started.html#configuring-a-database是您开始所需要的一切。

关于mysql 似乎不适用于我的新 Rails 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9405534/

相关文章:

php - Laravel Eloquent 仅选择不用作外键的数据

php - 销售后如何更新库存表

php - 使用 PHP 将 MySQL 变量插入 Google map

ruby-on-rails - 为什么 WEBrick 在 OSX 上处理我的请求这么慢?

ruby-on-rails - 从设计中覆盖注册 Controller 时,是否可以在创建操作中访问新创建的用户?

javascript - 当表中的值为 0 时,如何弹出错误消息?

ruby-on-rails-3 - RubyTutorial 10.5.2 Rspec测试微博分页

android - 将 SQLite 中的记录显示到 ListView 中

ios - SQLite WHERE 列 MATCH 参数绑定(bind)

android - 在 PreferenceFragment 中从数据库加载/保存设置