欢迎光临
我们一直在努力

php7.3.1-mysqli不支持caching_sha2_password

原本Linux7服务器上面的配置是Nginx1.15.*+php7.2.10+Mysql8.0.13,昨天晚上决定把php的版本升级为php7.3.1,安装过程还算顺利,只碰到3个小问题,昨天晚上已对碰到的3个问题的解决方案进行了整理,详看我昨天晚上的文章php7.3-编译安装过程中碰到的3个错误

在升级完以后,发现phpmyadmin的mysql数据库的管理页面用户登录进不去了,直接报如下错误:

mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client

我们知道mysql8.0.13默认的身份验证方式是:caching_sha2_password,在升级php后报对这种身份验证未知,那肯定就说明一点,mysqli扩展不支持新的caching_sha2_password 身份验证功能,到这里应该怎么办呢,总不能再换回php7.2.10吧!既然是身份验证的问题,那我们试着换下身份验证方式看可以吧!于是我按下面的方案更改了下身份验证方式。

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p -h 127.0.0.1
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 852
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER '你的用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 

更改验证方试为mysql_native_password以后,然后回来重新登录我们的phpmyadmin管理站点,Good,登录成功(如果是php7.2.1需要先在mysql的配置文件/etc/my.cnf下面添加default_authentication_plugin = mysql_native_password选项才可以登录)。

既然我们知道更改身份验证方式可以解决因为php7.3.1的mysqli扩展不支持caching_sha2_password 的这一问题,由于mysql8.0.13的默认验证方式就是caching_sha2_password,那么就会导致我们以后建立的用户的验证方式默认也肯定是这种验证方式,为了解决这一问题,我们可以在mysql的配置文件中mysqld部分添加以下语句使其以后建立的用户默认全采用mysql_native_password 这种验证方式。

  • 修改mysql配置文件 vi /etc/my.cnf
[mysqld]
default_authentication_plugin = mysql_native_password
  • 最后重启mysql数据库 service mysql restart
[root@localhost ~]# service mysql restart
Shutting down MySQL... SUCCESS! 
Starting MySQL..... SUCCESS! 
赞(3) 打赏
原创文章转载请注明出处:爱编程 » php7.3.1-mysqli不支持caching_sha2_password
分享到: 更多

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    仍旧提示 Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in C:\fastwork\Apache24\htdocs\init-mysql.php on line 14

    kam5年前 (2019-10-22)回复

爱编程、一个运维兼程序员的博客!

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏