项目在连接MySQL数据库的时候出现的报错如下
解决办法
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '000000';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
报错:ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> 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的host为%
将localhost换成%即可
mysql> alter user 'root'@'%' identified with mysql_native_password by '000000';
Query OK, 0 rows affected (0.00 sec)
参考文章:解决MySQL8.0报错Client does not support authentication protocol requested by server...问题-优快云博客