PHP:使用mysqli连接mysql

提示:

     使用 PHP 7.1.16 之前的版本或者 PHP 7.2(PHP 7.2.4 之前的版本), 需要将 MySQL 服务器的默认密码插件设置为:mysql_native_password。 否则,当你连接的时候就会看到类似这样的错误: The server requested authentication method unknown to the client [caching_sha2_password]。 即使你未使用 caching_sha2_password 也会这样。

发生这种错误的原因是,MySQL 8 服务器默认会使用 caching_sha2_password 扩展, 老版本的 PHP 驱动(mysqlnd)无法识别这个扩展。

例如,在mysql中操作:

use mysql;

alter user 'php'@'%' identified with mysql_native_password by 'php@world';

猜你喜欢

转载自blog.csdn.net/hefrankeleyn/article/details/85119958