首页 > 解决方案 > ActiveRecord::ConnectionNotEstablished: 拒绝访问

问题描述

想要  

消除这个错误,我要连接rails和MySQL

ActiveRecord::ConnectionNotEstablished: Access denied for user 'wdyluser'@'localhost' (using password: YES)

Mysql2::Error::ConnectionError: Access denied for user 'wdyluser'@'localhost' (using password: YES)

当前状态

我正在用rails制作一个应用程序。
DB 最初使用 SQLite,但决定迁移到 MySQL。

最后,当我输入这个命令时,我得到了上面的错误并卡住了。

bundle exec rake db:create

↓</p>

ActiveRecord::ConnectionNotEstablished: Access denied for user 'wdyluser'@'localhost' (using password: YES)

Mysql2::Error::ConnectionError: Access denied for user 'wdyluser'@'localhost' (using password: YES)

资源

配置/数据库.yml

default: &default
  adapter: mysql2
  database: wdyldb
  username: wdyluser
  password: 00000
  host: 127.0.0.1
  encoding: utf8

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default

宝石文件

gem 'mysql2'
# gem 'sqlite3', '~> 1.4'

我试过了

mysql -uwdyluser -p00000

↓</p>

ok(用户名和密码正确)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wdyldb             |
+--------------------+
2 rows in set (0.00 sec)

↓<br />存在

mysql> show grants for wdyluser@localhost;
+--------------------------------------------------------------+
| Grants for wdyluser@localhost                                |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO `wdyluser`@`localhost`                 |
| GRANT ALL PRIVILEGES ON `wdyldb`.* TO `wdyluser`@`localhost` |
+--------------------------------------------------------------+

↓<br /> 存在,有权限

环境

macOS BigSur 11.1
mysql Ver 8.0.23
ruby​​ 2.7.0p0
Rails 6.1.1

标签: mysqlruby-on-railsruby

解决方案


推荐阅读