2012-07-08 122 views
0

我正在设置一个基本的RoR应用程序。我所有的数据库都是MySQL和本地数据库,包括了yml文件。我试图访问一个基本的视图,但仍然得到ActiveRecord :: ConnectionNotEstablished错误。我究竟做错了什么?Ruby on Rails ActiveRecord :: ConnectionNotEstablished

# database.yml 
development: 
    adapter: mysql2 
    encoding: utf8 
    database: *****_dev 
    username: **** 
    password: ***** 
    host: 127.0.0.1 
    port: 3306 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    adapter: mysql2 
    encoding: utf8 
    database: *****_test 
    username: **** 
    password: ***** 
    host: 127.0.0.1 
    port: 3306 

production: 
    adapter: mysql2 
    encoding: utf8 
    database: *****_prod 
    username: **** 
    password: ***** 
    host: 127.0.0.1 
    port: 3306 

MySQL2在宝石文件:

gem 'mysql2', '~>0.3.10' 

所以,当转到输入:http://localhost:3000/controller/view我得到:ActiveRecord的:: ConnectionNotEstablished

我还能包括将是有益的?

在此先感谢。

+0

如果用本地主机替换127.0.0.1运作的?还有哪个版本的Rails? 3.2.6? – ScottJShea 2012-07-08 09:39:10

+0

如果我用localhost替换127.0.0.1,如果我尝试运行rake db:migrate,则会出现套接字错误。用127.0.0.1 rake db:migrate运行没有错误。另外,我在rails 3.2.2上。谢谢。 – analyticsPierce 2012-07-08 17:12:00

+0

你安装了apache和mysql吗? http:// localhost /之后的结果是什么? – chaitanya 2012-07-09 05:25:18

回答

1

看看你的/etc/mysql/my.cnf并检查mysql deamon的绑定地址。它可能不绑定到任何IP。然后它将使用unix套接字,这是快速的IP连接,...

绑定地址的选项名称是bind-address如果不匹配它不会绑定到任何地址。还要看看socket,它指定了unix套接字的路径。您可以使用这样的插座在database.yml

development: 
    adapter: mysql2 
    encoding: utf8 
    database: *****_dev 
    username: **** 
    password: ***** 
    socket: /path/to/the/socket/mysql.sock 

这应该为你做,...

相关问题