无法在 php 中连接到 mysql 8
Posted
技术标签:
【中文标题】无法在 php 中连接到 mysql 8【英文标题】:Not able to make connection to mysql 8 in php 【发布时间】:2019-02-12 14:44:50 【问题描述】:我正在尝试使用 php 连接到 mysql 服务器,但它给出了以下错误
Connection failed: The server requested authentication method unknown to the client
mysql服务器版本为8.0.12,php版本为7.2.9。 我的代码连接到 mysql 服务器
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "mypassword";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
echo "Connected successfully";
?>
在here 之前已经提出过这个问题,但该解决方案对我不起作用,所以我再次问这个问题。 谢谢
编辑:我现在重新安装了 php,它为相同的代码提供了以下内容
This page isn’t working
127.0.0.1 is currently unable to handle this request.
HTTP ERROR 500
【问题讨论】:
也许看看***.com/questions/49948350/phpmyadmin-on-mysql-8-0 还有dev.mysql.com/doc/refman/8.0/en/… 我还没有安装 phpMyAdmin @ChrisLear 不,但上下文看起来非常适用 也检查一下:dba.stackexchange.com/questions/34024/… 【参考方案1】:我也遇到过类似的问题,发现可以通过Workbench运行下面的代码来改变mysql认证
ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'new-password-here'
【讨论】:
以上是关于无法在 php 中连接到 mysql 8的主要内容,如果未能解决你的问题,请参考以下文章
使用go webservice在docker中连接到mysql时连接被拒绝
为啥在 C# .Net Core 3 中连接到 MySql 时出现错误