简体   繁体   English

尝试连接数据库时出错

[英]Error when trying to connect to database

So I'm trying to connect the database and I get this error 所以我试图连接数据库,但出现此错误

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /usr/local/zend/share/UserServer/register.php on line 2 警告:mysqli_connect():(HY000 / 1045):在第2行的/usr/local/zend/share/UserServer/register.php中,对用户'root'@'localhost'的访问被拒绝(使用密码:是)

Here's line 2 $conn = mysqli_connect("localhost","root","xxxx","db"); 这是第2行$conn = mysqli_connect("localhost","root","xxxx","db");

Not sure where to go on from here.... Also my credentials are 100% correct. 不知道从这里继续。...而且我的凭据也是100%正确。

You are trying to connect the database with the mysql user root@localhost,check if the user exists in your database: 您正在尝试使用mysql用户root @ localhost连接数据库,请检查该用户是否存在于数据库中:

select * from mysql.user where user='root' and host='localhost';

There will be a corresponding row if the user root@localhost exists. 如果用户root @ localhost存在,将有一个对应的行。

Looks like the application is not identifying "localhost". 看起来应用程序未标识“ localhost”。 Try these few options. 试试这些几个选项。 1) Try to connect using the ip 127.0.0.1 instead of localhost. 1)尝试使用IP 127.0.0.1代替localhost进行连接。 2) If you want to access via localhost itself, try to update the user table in mysql 2)如果要通过本地主机本身访问,请尝试在mysql中更新用户表

update mysql.user set host='%' where user='root';
flush privileges;

3) Found some tips in this link for PHP specific configurations. 3)在此链接中找到了一些针对PHP特定配置的提示。 I am not a PHP guy and so I do not know how to make this work. 我不是PHP专家,所以我不知道如何进行这项工作。 I hope you will understand. 希望您能理解。 http://madproject.com/general/connect-to-mysql-using-localhost-instead-of-127-0-0-1-on-a-mac/ http://madproject.com/general/connect-to-mysql-using-localhost-instead-of-127-0-0-1-on-a-mac/

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

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