Mysql2 ::错误:拒绝访问用户' rails_user' @' localhost' (使用密码:是)

时间:2016-12-31 15:40:00

标签: ruby-on-rails mysql2

我正在尝试创建一个数据库并将其与我的rails应用程序连接。

当我尝试检查我的数据库是否通过以下方式正确连接时:

rails db:schema:dump

它给了我ff错误:

Mysql2::Error: Access denied for user 'rails_user'@'localhost' (using password:
YES)
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)

这让我大吃一惊,因为我在创建数据库时使用了确切的密码:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: rails_user
  password: grace0512
  host: localhost

development:
  <<: *default
  database: test_project_development

# 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:
  <<: *default
  database: test_project_test

我试过这个:

grant all on simple_cms_development.* to 'rails_user'@'localhost' identified by '<password>';
flush privileges;

但没有解决我的问题。有什么帮助吗?

我真的需要解决这个问题才能继续前进!

2 个答案:

答案 0 :(得分:1)

你修好了吗?

我稍微改了一下并放了

    GRANT ALL PRIVILEGES ON demo_project_development.* to rails_user@localhost IDENTIFIED BY 'password';
    FLUSH PRIVILEGES; 

虽然我仍然收到Rails警告,但之后它成功完成了模式转储!

答案 1 :(得分:0)

您需要运行的SQL命令是:

GRANT ALL PRIVILEGES ON test_project_development.* to 'railsuser'@'localhost' 
IDENTIFIED BY 'grace0512';

请也立即执行以下命令以保持一致:

GRANT ALL PRIVILEGES ON test_project_test.* to 'railsuser'@'localhost' 
IDENTIFIED BY 'grace0512';

由于MySql会自动重新加载授权表,因此无需使用刷新特权。

如果这不起作用,在更新database.yml之后,是否在项目根目录的命令行中运行捆绑安装?如果是这样,请重新检查您是否拼错了用户名或密码。