PHP 8.3连接MySQL 8时遇caching_sha2_password认证未知错误求解决
已安装并运行PHP 8.3.7(经phpinfo()确认),尝试连接MySQL 8数据库时触发以下致命错误:
PHP Fatal error: Uncaught mysqli_sql_exception: The server requested authentication method unknown to the client [caching_sha2_password]
查阅资料得知PHP 8.3应该原生支持caching_sha2_password认证方式,但目前能找到的临时解决方法只有将MySQL用户强制改为已停用的mysql_native_password——这是过时特性,我更希望让原生的SHA认证功能正常工作,而非依赖旧方案。
未找到任何说明提及PHP需要特殊配置才能支持该认证方式,猜测自己遗漏了某些明显的配置项。
phpinfo()显示关键信息:
8.3.7 Client API library version mysqlnd 8.3.7
完整错误栈信息:
Fatal error:** Uncaught mysqli_sql_exception: The server requested authentication method unknown to the client [caching_sha2_password] in /[...]/testSO01.php:13 Stack trace: #0 /[...]/testSO01.php(13): mysqli_connect() #1 {main} thrown in /[...]/testSO01.php on line 13
内容的提问来源于stack exchange,提问作者Frédéric Vivien

