Rails、Ruby 1.9.3p0 和 mysql gem

Posted

技术标签:

【中文标题】Rails、Ruby 1.9.3p0 和 mysql gem【英文标题】:Rails, Ruby 1.9.3p0, and mysql gem 【发布时间】:2012-01-17 05:44:49 【问题描述】:

我正在运行 CentOS6 并从源代码安装了 Ruby,以及 Rails 和其他一些工作人员。

ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]  

rails -v
Rails 3.1.3

一些宝石:

*** 当地宝石 *** actionmailer (3.1.3, 2.3.14) 动作包(3.1.3、2.3.14) 活动模型(3.1.3) 活动记录(3.1.3、2.3.14) 活动资​​源(3.1.3、2.3.14) 主动支持(3.1.3、2.3.14) 归档-tar-minitar (0.5.2) 雷尔 (2.2.1) 大十进制 (1.1.0) 有弹性的城堡 java (1.5.0146.1) 建设者(3.0.0) 捆绑器 (1.0.21) 码雷 (0.9.7) 列化(0.3.5) edavis10-object_daddy (0.4.3) 厄鲁比斯 (2.7.0) 更快的csv(1.5.0) 菲(1.0.11) 远足 (1.2.1) 锄头 (2.12.4) i18n (0.6.0, 0.4.2) io 控制台 (0.3) jruby-openssl (0.7.4) json (1.5.4) linecache19 (0.5.13) 邮件 (2.3.0) 元类 (0.0.1) 哑剧类型 (1.17.2) 迷你测试(2.5.1) 摩卡(0.10.0) multi_json (1.0.4) mysql (2.8.1) mysql2 (0.3.11, 0.2.7) 网络 ldap (0.2.2) 多语言(0.3.3) 机架(1.3.5、1.1.2) 机架缓存 (1.1) 机架式 (0.8.3) 机架 SSL (1.3.2) 机架测试(0.6.1) 导轨(3.1.3、2.3.14) 铁路 (3.1.3) 耙子 (0.9.2.2) rdoc (3.9.4) rmagick (2.13.1) ruby-debug-base19 (0.11.26, 0.11.25) 红宝石调试19 (0.11.6) 红宝石-mysql (2.9.4) 红宝石-openid (2.1.4) ruby_core_source (0.1.5) rubygems 更新 (1.8.12) 红宝石树(0.5.2) 应该 (2.11.3, 2.10.3) 链轮 (2.0.3) sqlite3 (1.3.5, 0.1.1) sqlite3-ruby (1.3.3, 1.2.5) 雷神 (0.14.6) 倾斜 (1.3.3) 树顶 (1.4.10) tzinfo (0.3.31)

我需要 Rails 才能运行 chiliproject,但是在运行以下命令时

RAILS_ENV=production bundle exec rake db:migrate

我明白了:

!!!捆绑的 mysql.rb 驱动程序已从 Rails 2.2 中删除。请安装 mysql gem 并重试:gem install mysql。 耙中止! 无法加载这样的文件——mysql 任务:TOP => db:migrate => 环境 (通过使用 --trace 运行任务查看完整跟踪)

现在--trace:

RAILS_ENV=production bundle exec rake db:migrate --trace >> tmp/rake ** 调用 db:migrate (first_time) ** 调用环境(first_time) ** 执行环境 !!!捆绑的 mysql.rb 驱动程序已从 Rails 2.2 中删除。请安装 mysql gem 并重试:gem install mysql。 耙中止! 无法加载这样的文件——mysql /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/core_ext/kernel/requires.rb:7:in `block in require_library_or_gem' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/core_ext/kernel/requires.rb:5:in `require_library_or_gem' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/mysql_adapter.rb:61:in `mysql_connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `block (2 levels) in checkout' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `block in checkout' /usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection' /var/www/html/chiliproject/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb:218:in `quoted_left_column_name' /var/www/html/chiliproject/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb:94:in `acts_as_nested_set' /var/www/html/chiliproject/app/models/issue.rb:33:in `' /var/www/html/chiliproject/app/models/issue.rb:15:in `' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:184:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:291:in `require_or_load' /var/www/html/chiliproject/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb:133:in `require_or_load_with_engine_additions' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:451:in `load_missing_constant' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing_with_dependencies' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/inflector.rb:375:in `const_get' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/inflector.rb:375:in `block in constantize' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/inflector.rb:374:in `each' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/inflector.rb:374:in `constantize' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/core_ext/string/inflections.rb:162:in `constantize' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:157:in `observed_class' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:183:in `observed_classes' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:166:in `initialize' /usr/local/lib/ruby/1.9.1/singleton.rb:141:in `new' /usr/local/lib/ruby/1.9.1/singleton.rb:141:in `block in instance' :10:在“同步”中 /usr/local/lib/ruby/1.9.1/singleton.rb:139:in `instance' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:38:in `block in instantiate_observers' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:36:in `each' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-2.3.14/lib/active_record/observer.rb:36:in `instantiate_observers' /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:15:in `block in define_dispatcher_callbacks' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:182:in `call' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:182:in `evaluate_method' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:166:in `call' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:90:in `block in run' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:90:in `每个' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:90:in `run' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:276:in `run_callbacks' /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-2.3.14/lib/action_controller/dispatcher.rb:51:in `run_prepare_callbacks' /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/initializer.rb:631:in `prepare_dispatcher' /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/initializer.rb:185:in `process' /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/initializer.rb:113:in `run' /var/www/html/chiliproject/config/environment.rb:39:in `' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `block in require' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:547:in `new_constants_in' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:182:in `require' /usr/local/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/tasks/misc.rake:4:in `block in ' /usr/local/lib/ruby/1.9.1/rake/task.rb:205:in `call' /usr/local/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute' /usr/local/lib/ruby/1.9.1/rake/task.rb:200:in `each' /usr/local/lib/ruby/1.9.1/rake/task.rb:200:in `execute' /usr/local/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' /usr/local/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/rake/task.rb:176:in `block in invoke_prerequisites' /usr/local/lib/ruby/1.9.1/rake/task.rb:174:in `each' /usr/local/lib/ruby/1.9.1/rake/task.rb:174:in `invoke_prerequisites' /usr/local/lib/ruby/1.9.1/rake/task.rb:157:in `block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' /usr/local/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/rake/task.rb:144:in `invoke' /usr/local/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task' /usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level' /usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `each' /usr/local/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level' /usr/local/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling' /usr/local/lib/ruby/1.9.1/rake/application.rb:88:in `top_level' /usr/local/lib/ruby/1.9.1/rake/application.rb:66:in `block in run' /usr/local/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling' /usr/local/lib/ruby/1.9.1/rake/application.rb:63:in `run' /usr/local/bin/rake:32:in `' 任务:TOP => db:migrate => 环境

有人知道mysql gem 文件有什么问题吗?

我也尝试过像这样安装 mysql gem 文件

gem install ruby-mysql2 --no-rdoc --no-ri -- --with-mysql-config=/usr/bin/mysql_config

【问题讨论】:

【参考方案1】:

我只是遇到了类似的问题,你可能正在做我以前的事情:我使用“gem list”来确定安装了什么(它列出了*** LOCAL GEMS ***,就像你展示的那样)我看到了mysql,但是Gemfile 我的项目不需要 bundler 来安装 mysql

如果你只输入bundle show,它会列出'mysql'吗?如果不是,那么chiliproject 中的Gemfile 不会导致bundler 安装mysql。我发现这一切都非常令人困惑,直到我意识到我混淆了管理安装什么 gem 的不同方法。

如果您或其他人遇到同样的问题,那么也许这会有所帮助。 (也许这种糟糕的解释会鼓励一位铁路专家为我们详细阐述。)

换句话说,您本地安装的 gem 列表与安装在您应用的 bundle gem 中的列表不同(因此bundler 工具的名称来自)。当您运行您的应用程序并使用bundler 管理其依赖项时,您必须在bundler 范围内执行所有操作,以确保它们一起工作。当你这样做时,它实际上非常简单,并为你解决了很多问题,但如果你以前在没有使用 bundler 的应用程序上获得过经验,那么它只需要一点时间来适应。

【讨论】:

谢谢@normalocity - 这很有帮助。我是否正确,这允许用于生产的 bundle 与用于开发的 bundle 不同步? (如果是这样,那将帮助我找出另一个问题。) 实际上,developmentproduction 捆绑包之间应该没有区别。您是否遇到这种情况(即bundle show 在开发和生产中没有显示相同的内容)?除了仅用于测试的 gem(例如cucumberrspec 等)之外,列表应相同。 我的bundle show 列表是相同的。我想我会继续寻找问题;不是这样的。【参考方案2】:

对我有用的两个步骤:

    从 /libhttp://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/ 复制文件 libmySQL.dll在 c:/your/path/to/ruby/bin 中选择(在文件夹 /lib/ 中)(确保您的 ruby​​ bin 在您的系统 PATH 环境变量中)

    默认设置是为带有 ruby​​1.8 的 MySQL 提供的。如果您使用 MySQL 和 ruby​​1.9 运行 Redmine,请在 /config/database.yml 文件中将适配器名称替换为 mysql2 http://www.redmine.org/issues/10566

【讨论】:

【参考方案3】:

就在捆绑安装试试这个>>

bundle install --without=test development sqlite postgres mysql rmagick

这将安装所有必需的基本依赖项,mysql2 数据库适配器 原因 mysql 适配器与 Ruby 1.9 不兼容

别忘了修改config/database.yml --> s/mysql/mysql2

\o/

【讨论】:

我刚刚在一个旧项目(ruby 1.8)上遇到了这个问题,database.yml 就是问题所在!忘记将mysql 替换为mysql2

以上是关于Rails、Ruby 1.9.3p0 和 mysql gem的主要内容,如果未能解决你的问题,请参考以下文章

rails 服务器无法在 OSX 10.6.5 上使用 rvm 和 ruby​​ 1.9.2-p0 启动 mysql2

如何使用 RVM 更改我的 Ruby 版本?

在 ubuntu 12.02 上设置 rails 4 ruby​​ 2.0

ruby on rails创建的页面訪问很慢

如何设置 webrick 服务器以使用 ruby​​ 1.9.3?

chardinjs 不在 ruby​​ on rails 中工作