在我的 OS X 开发笔记本电脑上一切正常。
将应用程序部署到生产环境,它会按预期运行和显示数据。
但是,当我尝试在生产服务器上运行 Rails控制台时,我收到一个错误...
$ rails console -e production
/opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:
in `connect': Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) (Mysql2::Error)
from /opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
from /opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
我尝试socket: /tmp/mysql.sock
从 database.yml 中删除——结果相同。
虽然应用程序运行,但我确实需要能够访问生产中的控制台以执行某些任务。
我能够使用 MySQL 命令行客户端连接到 MySQL 服务器。
红宝石 1.9.3p125
导轨 3.2.2
mysql2 宝石 0.3.11
MySQL服务器:5.1.61
生产主机:Linux 2.6.32-220.4.2.el6.x86_64
数据库.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: con_app_rails_3_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: con_app_rails_3_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: dbhost
database: con_app_rails_3_production
pool: 5
username: xxxx
password: xxxx
socket: /tmp/mysql.sock