简体   繁体   English

rails db:migrate rails已中止! Mysql2 :: Error:用户'root'@'localhost'的访问被拒绝(使用密码:是)

[英]rails db:migrate rails aborted! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES)

I'm running this migration: 我正在运行此迁移:

class CreateAdmins < ActiveRecord::Migration[5.1]
  def change
    create_table :admins do |t|

      t.string "first_name" :limit => 30
      t.string "last name", :limit => 30
      t.string "email", :default => '', :null => false
      t.string "password" ,:limit => 40
      t.timestamps

    end
  end

  def down
    drop_table :admins
  end
end

I get an error saying: 我收到一条错误消息:

rails db:migrate rails aborted! rails db:migrate rails已中止! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: YES) Mysql2 :: Error:用户'root'@'localhost'的访问被拒绝(使用密码:是)

You should update your database.yml file, in the config-directory. 您应该在配置目录中更新database.yml文件。 The error is caused by mysql responding with an authentication error, for your root user. 该错误是由mysql对您的root用户响应的身份验证错误引起的。 You might wanna check http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database for information on the database.yml syntax. 您可能想查看http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database以获得有关database.yml语法的信息。

You can furthermore check and validate the login in shell by running mysql -u root -p and try entering your password. 您还可以通过运行mysql -u root -p并尝试输入密码来检查和验证Shell中的登录。

For the first, this is correct migration code: 首先,这是正确的迁移代码:

class CreateAdmins < ActiveRecord::Migration[5.1]
  def self.up
    create_table :admins do |t|
      t.string :first_name, limit: 30
      t.string :last_name, limit: 30
      t.string :email, default: '', null: false
      t.string :password ,limit: 40

      t.timestamps
    end
  end

  def self.down
    drop_table :admins
  end
end

or just change difference 或只是改变 差异

class CreateAdmins < ActiveRecord::Migration[5.1]
  def change
    create_table :admins do |t|
      t.string :first_name, limit: 30
      t.string :last_name, limit: 30
      t.string :email, default: '', null: false
      t.string :password ,limit: 40

      t.timestamps
    end
  end
end

About error, your database.yml for development env, should looks like this: 关于错误,用于开发环境的database.yml应该如下所示:

development:
  adapter: mysql2
  encoding: utf8
  database: your_db_name
  username: your_user
  password: your_password
  host: 127.0.0.1
  port: 3306

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 rake db:迁移rake中止了! Mysql2 ::错误:用户&#39;simple_cms&#39;@&#39;localhost&#39;拒绝访问(使用密码:YES) - rake db:migrate rake aborted! Mysql2::Error: Access denied for user 'simple_cms'@'localhost' (using password: YES) 用户 &#39;root&#39;@&#39;localhost&#39; 拒绝 Rails 和 Mysql2 访问(使用密码:NO) - Rails and Mysql2 Access denied for user 'root'@'localhost' (using password: NO) Mysql2::Error::ConnectionError: Access denied for user &#39;rails_user&#39;@&#39;localhost&#39;(使用密码:YES) - Mysql2::Error::ConnectionError: Access denied for user 'rails_user'@'localhost' (using password: YES) Ruby on Rails-用户&#39;simple_cms&#39;@&#39;localhost&#39;的Mysql2 :: Error访问被拒绝(使用密码:是) - Ruby on rails - Mysql2::Error Access denied for user 'simple_cms'@'localhost' (using password: YES) Mysql2 ::错误访问被拒绝用户&#39;root&#39;@&#39;localhost&#39;(使用密码:NO)ruby on rails - Mysql2::Error Access denied for user 'root'@'localhost' (using password: NO) ruby on rails Mysql2 :: Error-用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是) - Mysql2::Error - Access denied for user 'root'@'localhost' (using password: YES) # <Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)> - #<Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)> Rails mysql 用户'root'@'localhost'的访问被拒绝(使用密码:否)错误 - Rails mysql Access denied for user 'root'@'localhost' (using password: NO) error 用户 &#39;root&#39;@&#39;localhost&#39; 访问被拒绝(使用密码:YES)(Mysql::Error) - Access denied for user 'root'@'localhost' (using password: YES) (Mysql::Error) Locall MySQL数据库登录错误:用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是) - Locall MySQL DB login Error : Access denied for user 'root'@'localhost' (using password: YES)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM