Rails 3.2.13 应用在共享主机 Mysql 更新后失败

Rails 3.2.13 app fails after shared host Mysql update

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

最近他们将 Mysql 更新为 Mysql2,之后我收到错误:

Ruby (Rack) application could not be started

以及具体的:

Error message:
(Mysql2::Error)

我的设置:

捆绑表演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

Gemfile:

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 并将端口号 3306 添加到我的 database.yml 轻松解决了这个问题 *郑重声明,我的应用程序位于 Bluehost 的共享主机上。

上一个 database.yml:

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

当前 database.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