- cmd里输入mysql -u root -p
- 输入密码
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
- 或者ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
- 最后刷新FLUSH PRIVILEGES;
若出现RROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
则输入命令查看select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
这里root对应%所以修改
PS:MySQL8 之前的版本中加密规则是mysql_native_password,而在MySQL8之后,加密规则是caching_sha2_password