PHP 7.2.2 + mysql 8.0 PDO 给出:客户端未知的身份验证方法 [caching_sha2_password]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49083573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP 7.2.2 + mysql 8.0 PDO gives: authentication method unknown to the client [caching_sha2_password]
提问by zioMitch
I'm using php 7.2.2 and mysql 8.0.
我正在使用 php 7.2.2 和 mysql 8.0。
When I try to connect with the right credential I get this error:
当我尝试使用正确的凭据连接时,出现此错误:
PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
Need help to troubleshoot the problem.
需要帮助来解决问题。
采纳答案by D0rm1nd0
回答by Reid
Found this somewhere, don't remember where (or I would credit), but it works for me until MySQL 8 gets better.
在某处找到了这个,不记得在哪里(或者我会相信),但它对我有用,直到 MySQL 8 变得更好。
In MySQL shell (command prompt, whatever):
在 MySQL shell(命令提示符,无论如何)中:
CREATE USER username@localhost identified with mysql_native_password by 'password';
Where usernameis the username and passwordis the password for that user.
其中username是用户名,password是该用户的密码。
Then you can add permissions in the shell - or in the Workbench as the user now exists with Authentication Type: Standard.
然后您可以在 shell 中添加权限 - 或者在 Workbench 中添加权限,因为用户现在以身份验证类型存在:标准。
回答by Szekelygobe
alter user 'username'@'localhost' identified with mysql_native_password by 'password';
As suggested by ailionx
here : https://github.com/laradock/laradock/issues/1390
正如ailionx
这里所建议的:https: //github.com/laradock/laradock/issues/1390
回答by Leonardo Beal
In order to use mySQL 8 (with the new authentication method) you could just upgrade your PHP.
为了使用 mySQL 8(使用新的身份验证方法),您只需升级 PHP。
MySQL 8
When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server's default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used.
MySQL 8
当运行 7.1.16 之前的 PHP 版本或 7.2.4 之前的 PHP 7.2 时,将 MySQL 8 Server 的默认密码插件设置为 mysql_native_password 否则您将看到类似于 The server requests authentication method unknown to the client [caching_sha2_password] 的错误,即使在 caching_sha2_password 时未使用。