我是MySQL和Rails的新手。我正在阅读关于Lynda(Ruby on Rails 5)的课程,我遇到了打嗝。创建数据库后,它让我启动MySQL和Puma。我尝试访问localhost:3000但是我收到以下错误:
Mysql2::Error (Access denied for user 'rails_user'@'localhost' to database 'simple_cms_development'):
看起来一切正常,MySQL和Puma都开始了:
Johns-MBP:simple_cms johnerickson$ mysql.server start
Starting MySQL
SUCCESS!
Johns-MBP:simple_cms johnerickson$ rails s
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.0 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
* List item
以下是我的database.yml文件:
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: rails_user
password: ***The password works***
host: localhost
development:
<<: *default
database: simple_cms_development
我查看了Stack Overflow并看到其他人遇到了类似的问题,但它似乎是一个密码问题,我没有。任何帮助将不胜感激。
答案 0 :(得分:2)
此特定用户没有足够的权限访问数据库。在mysql提示符下运行以下命令后尝试。您可能必须以root身份或其他管理员用户身份登录才能运行此命令。
grant all on simple_cms_development.* to 'rails_user'@'localhost' identified by '<password>';
flush privileges;