【发布时间】:2026-01-26 04:40:02
【问题描述】:
使用 mysql db 运行 rails 时出现此错误。基本上它没有授予root用户访问权限。我不知道为什么会这样,并且已经坚持了一段时间。
Mysql2::Error (Access denied for user 'root'@'localhost' (using password: YES)):
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.7ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.7ms)
我的 Database.yml 文件发布在下面供您参考。我不确定如何检查 MYSQL 自动分配的密码?会不会是我的电脑登录密码?无论如何我如何检查它。我也不能简单地在我的命令行上键入 mysql 我必须输入整个路径才能访问它。我该如何改变它。最重要的是,我想知道如何解决此访问被拒绝问题。谢谢你。在 mac 上使用 mysql 5.5。 x86_64 构建。
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
# 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
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
【问题讨论】:
标签: mysql ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1