PHP 与 MySQL 8.0+ 错误:服务器请求客户端未知的身份验证方法 [英] PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client

查看:42
本文介绍了PHP 与 MySQL 8.0+ 错误:服务器请求客户端未知的身份验证方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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():服务器请求客户端未知的身份验证方法 [caching_sha2_password] 在 D:\xampp\htdocs\reg\server.php 第 10 行

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

我该如何解决这个问题?

How can I fix this problem?

推荐答案

@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 用户登录到您的数据库,请将上述命令中的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.

数字海洋在这里进行了更多阐述 安装Mysql

Digital ocean expounds some more on this here Installing Mysql

这篇关于PHP 与 MySQL 8.0+ 错误:服务器请求客户端未知的身份验证方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆