RubyonRails服务器无法连接到mysql

RubyonRails服务器无法连接到mysql,mysql,ruby-on-rails-3,Mysql,Ruby On Rails 3,各位。 我正在尝试在macOS X上设置rails 3项目,使用mysql作为数据库。但是,我收到下一个错误: /usr/local/bundle/gems/activerecord-3.2.22.5/lib/active\u record/connection\u adapters/abstract/connection\u specification.rb:68:in connection\u url\u to\u hash:nil:NilClass的未定义方法'sub'(NoMethodE

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

/usr/local/bundle/gems/activerecord-3.2.22.5/lib/active\u record/connection\u adapters/abstract/connection\u specification.rb:68:in connection\u url\u to\u hash:nil:NilClass的未定义方法'sub'(NoMethodError)

config/database.yml


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

从您共享的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

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

我在我的
.env
文件中注释了环境变量
数据库URL
。此外,我还通过以下方式配置了我的
数据库.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

是否可以在Ruby中包含一个导致此问题的最小示例?我只是尝试使用foreman启动服务器,因此我不确定我可以提供哪些代码是的,我在这里错配了,主机存在于我的配置中您的数据库用户有密码吗?没有,我在.env MYSQL\u ALLOW\u EMPTY\u PASSWORD=true中指定了,在我还试图用单个url替换主机、端口和数据库之前没有为root添加任何密码,但id没有任何意义url:jdbc:mysql://root@localhost:3306/heart\u developments请尝试在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