尝试连接到数据库时出错

时间:2014-04-24 01:28:14

标签: php mysql database connection localhost

所以我正在尝试连接数据库,我收到此错误

  

警告:mysqli_connect():( HY000 / 1045):第2行的/usr/local/zend/share/UserServer/register.php中的用户“root”@“localhost”(使用密码:YES)拒绝访问

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

不确定从何处开始....还有我的凭据100%正确。

2 个答案:

答案 0 :(得分:0)

您正在尝试使用mysql用户root @ localhost连接数据库,检查数据库中是否存在该用户:

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

如果用户root @ localhost存在,则会有相应的行。

答案 1 :(得分:0)

看起来应用程序没有识别" localhost"。尝试这几个选项。 1)尝试使用ip 127.0.0.1而不是localhost进行连接。 2)如果要通过localhost本身访问,请尝试更新mysql中的用户表

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

3)在此链接中找到了针对PHP特定配置的一些提示。我不是一个PHP人,所以我不知道如何使这项工作。我希望你能理解。 http://madproject.com/general/connect-to-mysql-using-localhost-instead-of-127-0-0-1-on-a-mac/

相关问题