Mysql Ruby on Rails ActiveRecord::ConnectionNotEstablished
我正在建立一个基本的RoR应用程序。我所有的数据库都是MySQL和本地数据库,包括我的数据库和yml文件。我正在尝试访问一个基本视图,但仍然收到ActiveRecord::ConnectionNotesAblished错误。我做错了什么Mysql Ruby on Rails ActiveRecord::ConnectionNotEstablished,mysql,ruby-on-rails,Mysql,Ruby On Rails,我正在建立一个基本的RoR应用程序。我所有的数据库都是MySQL和本地数据库,包括我的数据库和yml文件。我正在尝试访问一个基本视图,但仍然收到ActiveRecord::ConnectionNotesAblished错误。我做错了什么 # database.yml development: adapter: mysql2 encoding: utf8 database: *****_dev username: **** password: ***** host: 127
# 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
I get:ActiveRecord::ConnectionNotEstablished
我还可以包括哪些有帮助的内容
提前感谢。查看您的
/etc/mysql/my.cnf
并检查mysql deamon的绑定地址。它可能不绑定到任何ip。然后它将使用unix套接字,这比ip连接更快
绑定地址的选项名为绑定地址
,如果没有匹配项,则不会绑定到任何地址。还要查找指定unix套接字路径的socket
。您可以在数据库.yml中像这样使用套接字
development:
adapter: mysql2
encoding: utf8
database: *****_dev
username: ****
password: *****
socket: /path/to/the/socket/mysql.sock
这对您来说应该可以了,…如果您用localhost替换127.0.0.1,这样做有效吗?还有什么版本的Rails?3.2.6?如果我用localhost替换127.0.0.1,如果我尝试运行rake db:migrate,就会出现套接字错误。使用127.0.0.1 rake db:migrate运行时不会出错。另外,我在rails 3.2.2上。谢谢。你安装了apache和mysql吗?结果如何