简体   繁体   English

PHP-Mysql:无法连接到数据库

[英]PHP - Mysql: can't connect to database

I've setup mysql server 8.0, Apache2.4, php 7.2 and created a simple database. 我已经安装了mysql服务器8.0,Apache2.4,php 7.2,并创建了一个简单的数据库。

As a start I am trying to write a php code for connecting to the database but i can't figure it out. 首先,我试图编写一个php代码以连接数据库,但我不知道。 My code: 我的代码:

<?php
$con = mysqli_connect("localhost","Don","password","db1");

if (!$con) {
echo "Error: " . mysqli_connect_error();
exit();
}

echo 'Connected to MySQL';
?>

I get Error: The server requested authentication method unknown to the client. 我收到错误消息:服务器请求客户端未知的身份验证方法。

I've tried several things: connect to root, 192.168.0.1 instead of localhost but nothing is working. 我已经尝试了几件事:连接到root,192.168.0.1而不是localhost,但是没有任何作用。

Any ideas? 有任何想法吗? Thanks. 谢谢。

(post for someone who has the same problem) (发给有相同问题的人)

i searched about the old password issue but i couldnt find the old_passwords var, not even in my.cnf file. 我搜索了旧密码问题,但是我找不到old_passwords var,甚至在my.cnf文件中也找不到。

so what i did was uninstalling mysql server 8.0 and installing 5.7.2 and it worked. 所以我所做的是卸载mysql服务器8.0并安装5.7.2,它可以正常工作。

ps i didnt configure anything differently while setting up the 5.7.2 version. PS:我在设置5.7.2版本时没有进行任何其他配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM