mysql - 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
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
解决方案
推荐阅读
- firebase - 提高 Firebase 存储的性能
- r - R中的组中位数
- stripe-payments - 如何解决错误 Unsupported Gateway Type for Storage in whmcs using stripe?
- c++ - 使用推力根据索引更改某些元素的值
- lua - NodeMCU lua:adc.readvdd33() 在 ESP8266 上总是返回 65535
- html - 将文本放在切换按钮旁边的更好方法
- java - 在提交表单的同一 jsp 中显示成功消息
- javascript - 处理类构造函数中的 promise 错误
- redirect - 将子域重定向到 Odoo 数据库
- elasticsearch - 无法更改 LXC 上的 vm.max_map_count