【问题标题】:Ruby on Rails ActiveRecord::ConnectionNotEstablishedRuby on Rails ActiveRecord::ConnectionNotEstablished
【发布时间】:2012-07-09 22:21:36
【问题描述】:

我正在设置一个基本的 RoR 应用程序。我所有的数据库都是 MySQL 和本地的,包括我的数据库,yml 文件。我正在尝试访问基本视图,但仍然收到 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

gem 文件中的 MySQL2:

gem 'mysql2', '~>0.3.10'

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

我还可以添加哪些有用的信息?

提前致谢。

【问题讨论】:

  • 如果将 127.0.0.1 替换为 localhost 是否有效?还有什么版本的Rails? 3.2.6?
  • 如果我将 127.0.0.1 替换为 localhost,如果我尝试运行 rake db:migrate,则会收到套接字错误。使用 127.0.0.1 rake db:migrate 运行没有错误。另外,我在rails 3.2.2上。谢谢。
  • 你安装了apache和mysql吗? localhost之后的结果是什么

标签: mysql ruby-on-rails


【解决方案1】:

查看您的/etc/mysql/my.cnf 并检查mysql 守护程序的绑定地址。它可能不绑定到任何ip。然后它将使用比 ip 连接更快的 unix 套接字,...

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

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

那应该为你做,...

【讨论】:

    猜你喜欢
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多