使用mysql连接数据库的时候报错

	PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2059] Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory in /root/index.php:2
Stack trace:
#0 /root/index.php(2): PDO->__construct('mysql:host=125....', 'username', 'password')
#1 {main}
	thrown in /root/index.php on line 2

这是Mysql 8的用户密码加密方式出现的问题,我创建用户是采用之前版本的做法

CREATE USER 'username'@'host' identified by 'password';

有两种方式解决

1.修改加密方式:ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
2.修改用户的密码:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '{NewPassword}';

旧版本的授权语法如下

GRANT ALL PRIVILEGES ON test.* to 'test'@'%' identified by 'test123'; 

Mysql 8授权必须把后面的identified部分去掉

GRANT ALL PRIVILEGES ON test.* to 'test'@'%'; 

不熟千万别随便升级,都是心累。