Ruby on Rails服务器无法连接到mysql

时间:2018-05-20 11:01:59

标签: mysql ruby-on-rails-3

大家。 我正在尝试使用mysql作为数据库在macOS X上设置rails 3项目。但是,我收到了下一个错误:

/usr/local/bundle/gems/activerecord-3.2.22.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in connection_url_to_hash&#39 ;: undefined method`sub'对于nil:NilClass(NoMethodError)

  

配置/ database.yml的

default: &default
  adapter: mysql2
  pool: 5
  encoding: utf8
  min_messages: warning
  timeout: 5000
  username: root
  password:
  database: heart_development
  host: localhost

有人可以建议如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

从您共享的database.yml和发布的日志中,似乎无法找到数据库所在的路径。

将database.yml更改为

  default: &default
  adapter: mysql2
  pool: 5
  encoding: utf8
  min_messages: warning
  timeout: 5000
  username: root
  password:
  database: heart_development
  host: localhost

数据库必须连接的指定主机。

答案 1 :(得分:0)

我在DATABASE_URL文件中评论了环境变量.env。我还在下一个方面配置了database.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: heart_development
  pool: 5
  username: root
  password:
  host: localhost
  port: 3306

test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: heart_test
  pool: 5
  username: root
  password:
  host: localhost
  port: 3306

production:
  adapter: mysql2
  encoding: utf8cm
  reconnect: false
  database: heart_production
  pool: 5
  username: root
  password:
  host: localhost
  port: 3306