【问题标题】:Rails 3.2.13 app fails after shared host Mysql update共享主机 Mysql 更新后 Rails 3.2.13 应用程序失败
【发布时间】:2015-01-30 07:28:59
【问题描述】:

我在 Justhost 服务器上有两个 Rails 3.2.13 应用程序。

最近他们将Mysql更新为Mysql2,之后出现错误:

Ruby (Rack) application could not be started

具体:

Error message:
(Mysql2::Error)

我的设置

bundle show mysql 轮流:/home3/ecotec11/rails_apps/ecotechno/vendor/bundle/ruby/1.9.3/gems/mysql2-0.3.16

database.yml

production:
  adapter: mysql2
  encoding: utf8
  reconnect: true
  database: database_name
  pool: 5
  username: username
  password: password
 # socket: /tmp/mysql.sock

宝石文件

gem 'mysql2'

基本上,当我联系支持人员时,他们说他们无法帮助我。

错误的完整回溯:

0   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/mysql2-0.3.16/lib/mysql2/client.rb  24  in `initialize_ext'
1   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/mysql2-0.3.16/lib/mysql2/client.rb  24  in `initialize'
2   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/mysql2_adapter.rb 16  in `new'
3   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/mysql2_adapter.rb 16  in `mysql2_connection'
4   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   315 in `new_connection'
5   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   325 in `checkout_new_connection'
6   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   247 in `block (2 levels) in checkout'
7   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   242 in `loop'
8   /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   242 in `block in checkout'
9   /usr/lib64/ruby/1.9.3/monitor.rb    211 in `mon_synchronize'
10  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   239 in `checkout'
11  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   102 in `block in connection'
12  /usr/lib64/ruby/1.9.3/monitor.rb    211 in `mon_synchronize'
13  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   101 in `connection'
14  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb   410 in `retrieve_connection'
15  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_specification.rb  171 in `retrieve_connection'
16  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_specification.rb  145 in `connection'
17  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/model_schema.rb   310 in `clear_cache!'
18  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activerecord-3.2.16/lib/active_record/railtie.rb    103 in `block (2 levels) in '
19  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/callbacks.rb    418 in `_run__4470304995410275411__prepare__777669663684257344__callbacks'
20  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/callbacks.rb    405 in `__run_callback'
21  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/callbacks.rb    385 in `_run_prepare_callbacks'
22  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/callbacks.rb    81  in `run_callbacks'
23  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb    74  in `prepare!'
24  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb    48  in `prepare!'
25  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/application/finisher.rb   47  in `block in '
26  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/initializable.rb  30  in `instance_exec'
27  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/initializable.rb  30  in `run'
28  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/initializable.rb  55  in `block in run_initializers'
29  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/initializable.rb  54  in `each'
30  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/initializable.rb  54  in `run_initializers'
31  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/application.rb    136 in `initialize!'
32  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/railties-3.2.16/lib/rails/railtie/configurable.rb   30  in `method_missing'
33  /home3/ecotec11/rails_apps/technorent/config/environment.rb 10  in `'
34  config.ru   3   in `require'
35  config.ru   3   in `block in
'
36  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/rack-1.4.5/lib/rack/builder.rb  51  in `instance_eval'
37  /home3/ecotec11/rails_apps/technorent/vendor/bundle/ruby/1.9.3/gems/rack-1.4.5/lib/rack/builder.rb  51  in `initialize'
38  config.ru   1   in `new'
39  config.ru   1   in `
'
40  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb  225 in `eval'
41  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb  225 in `load_rack_app'
42  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb  157 in `block in initialize_server'
43  /etc/httpd/modules/passenger/lib/phusion_passenger/utils.rb 563 in `report_app_init_status'
44  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb  154 in `initialize_server'
45  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb   204 in `start_synchronously'
46  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb   180 in `start'
47  /etc/httpd/modules/passenger/lib/phusion_passenger/rack/application_spawner.rb  129 in `start'
48  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb 253 in `block (2 levels) in spawn_rack_application'
49  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb    132 in `lookup_or_add'
50  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb 246 in `block in spawn_rack_application'
51  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb    82  in `block in synchronize'
52      prelude>    10:in `synchronize'
53  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server_collection.rb    79  in `synchronize'
54  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb 244 in `spawn_rack_application'
55  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb 137 in `spawn_application'
56  /etc/httpd/modules/passenger/lib/phusion_passenger/spawn_manager.rb 275 in `handle_spawn_application'
57  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb   357 in `server_main_loop'
58  /etc/httpd/modules/passenger/lib/phusion_passenger/abstract_server.rb   206 in `start_synchronously'
59  /etc/httpd/modules/passenger/helper-scripts/passenger-spawn-server  99  in `

在应用程序日志中:

Connecting to database specified by database.yml
Connecting to database specified by database.yml
Connecting to database specified by database.yml
Connecting to database specified by database.yml
Connecting to database specified by database.yml
Connecting to database specified by database.yml
Connecting to database specified by database.yml

我检查了数据库是否存在。有密码的用户是有效的。

我测试了控制台是否工作。是的,它有效。

rails console production

我能够创建新记录并更新现有记录!

这让我觉得有什么问题呢?如果只是为了 webservice 数据库不工作?

那么这个问题是从哪里来的呢?

任何提示都会很棒。 谢谢

【问题讨论】:

  • 如果您之前使用的是 mysql,并且 Gemfile 已更新为使用 mysql2,您是否也将您的 config/database.yml 更新为使用 mysql2?
  • @jvnill 我忘了在 Justhost 更新之前提到一切都与 gem 'mysql2' 一起工作,但是在这次更新之后我没有改变代码。
  • 也许你只需要重新安装 mysql2 gem。卸载所有版本的mysql2 gem,然后运行bundle
  • @jvnill 谢谢。我试过这个。不用找了。也许我只需要更改我的数据库?喜欢PostgreSQL,除了Mysql,我只能选择一个。
  • 如果这对您来说是一个选项,那么就去做吧,但是对于那些访问此问题以寻找答案的其他开发人员来说,很高兴知道究竟是什么导致了这个问题。

标签: mysql ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

我通过恢复到 mysql 并将端口号 3306 添加到我的 database.yml 轻松解决了这个问题 *作为记录,我的应用在 Bluehost 上的共享主机上。

以前的database.yml:

development:
adapter: mysql2
database: my_db
encoding: utf8
username: my_username
password: my_password
host: localhost
reconnect: true

当前数据库.yml:

development:
adapter: mysql
database: my_db
encoding: utf8
username: my_username
password: my_password
host: 127.0.0.1
reconnect: true
socket: mysql
port: 3306

【讨论】:

  • 我遇到了很多 mysql 故障,所以冒险将我的应用程序更新到 Rails4.1。 (这样做只花了几个小时!)我还将 mysql2 gem 锁定在 v3.0.16(bluehost 推荐)。还有一件事,我在我的 database.yml 中添加了:socket: /var/lib/mysql/mysql.sock。 :)
  • 为我工作,谢谢!虽然使用 host:localhost 而不是 127.0.0.1,并且还使用了提到的套接字 /var/lib/mysql/mysql.sock。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-25
相关资源
最近更新 更多