PHP与MySQL 8.0+错误:服务器请求客户端未知的身份验证方法 [英] PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client
问题描述
我正在PHP 7.0上运行MySQL版本8.
I'm running MySQL version 8 on PHP 7.0.
当我尝试从PHP连接到数据库时出现以下错误:
I'm getting the following error when I try to connect to my database from PHP:
连接错误:SQLSTATE [HY000] [2054]服务器请求客户端未知的身份验证方法
Connect Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
PHP可能显示此错误
PHP might show this error
警告:mysqli_connect():服务器在第10行的D:\ xampp \ htdocs \ reg \ server.php中请求客户端[caching_sha2_password]未知的身份验证方法
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in D:\xampp\htdocs\reg\server.php on line 10
如何解决此问题?
推荐答案
@mohammed,通常归因于您的mysql数据库正在使用的身份验证插件.
@mohammed, this is usually attributed to the authentication plugin that your mysql database is using.
默认情况下,由于某种原因,mysql 8默认插件是auth_socket.应用程序通常会期望使用密码登录到您的数据库.
By default and for some reason, mysql 8 default plugin is auth_socket. Applications will most times expect to log in to your database using a password.
如果尚未更改mysql默认身份验证插件,则可以通过以下方法进行更改:
1.以root用户身份登录到mysql
2.运行以下sql命令:
If you have not yet already changed your mysql default authentication plugin, you can do so by:
1. Log in as root to mysql
2. Run this sql command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
用您的root密码替换"password".如果您的应用程序没有以root用户身份登录到数据库,请用应用程序使用的用户替换上述命令中的'root'用户.
Replace 'password' with your root password. In case your application does not log in to your database with the root user, replace the 'root' user in the above command with the user that your application uses.
Digital ocean expounds some more on this here Installing Mysql
这篇关于PHP与MySQL 8.0+错误:服务器请求客户端未知的身份验证方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!