【问题标题】:Mysql2::Error: Access denied for user 'rails_user'@'localhost' (using password:YES)Mysql2::Error: Access denied for user 'rails_user'@'localhost' (使用密码:YES)
【发布时间】:2016-12-31 15:40:00
【问题描述】:

我正在尝试创建一个数据库并将其与我的 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;

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

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

【问题讨论】:

  • 我知道这是一个很长的镜头,但请确保 password: grace0512 之后没有空格 .. 可以肯定的是,将所有值包含在 "" 中。 password: "grace0512"
  • 对我不起作用。

标签: ruby-on-rails mysql2


【解决方案1】:

你修好了吗?

我稍微改了一下,放了

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

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

【讨论】:

    【解决方案2】:

    你需要运行的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 后在项目根目录的命令行上运行了 bundle install?如果是这样,请重新检查您是否拼错了用户名或密码。

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 1970-01-01
      • 2018-07-27
      • 2021-12-27
      相关资源
      最近更新 更多