MySQL错误1045访问被拒绝 [英] MySQL Error 1045 Access Denied

查看:563
本文介绍了MySQL错误1045访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好

我在本地Windows 7 PC上编写了以下代码块,并尝试运行它.不幸的是,我收到了:

I wrote the code block below on my local Windows 7 PC and tried to run it. Unfortunately, I received:

Connect Error (1045) Access denied for user 'dbuser'@'myhost(using password: YES)

我已为此数据库模式使用localhost和%授予dbuser插入,选择,更新和执行.我也可以从服务器上的命令行使用mysql -u dbuser -p.

I have granted dbuser Insert, Select, Update, and Execute using both localhost and % for this database schema. I am able to mysql -u dbuser -p from command line on server as well.

这是代码块:

<?php
/* Set Variables */
$host="serveripaddress";
$db="dbname"; 
$username="dbuser";
$pass="pass";

/* Attempt to connect */
$mysqli=new mysqli($host,$username,$pass,$db);
if (mysqli_connect_error()){
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();

}
?>

我很难理解上面的代码块是否导致了我的错误,或者是否需要在服务器上执行某些操作.谁能建议一些调查领域?

I'm having difficulty understanding whether the above code block is causing my error, or whether there's something required to be done on the server. Can anyone suggest some areas of investigation?

谢谢, 席德

推荐答案

请确保如果您在MySQL中为GRANT使用主机名,则MySQL可以正确地将该主机名解析为您要连接的IP.

Make sure that if you're using a hostname for the GRANT in MySQL, that MySQL can properly resolve that hostname to the IP you're connecting from.

例如,如果您这样做

GRANT blah ON *.* to user@somehost

您必须记住,MySQL不会看到"somehost",它将看到一个IP地址.必须进行反向查找才能获取主机名,如果IP没有反向映射,或者映射到完全不同的内容,则MySQL将不会提供访问权限.

you have to remember that MySQL won't see 'somehost', it'll see an IP address. It'll have to do a reverse lookup to get a hostname, and if the IP either doesn't have a reverse mapping, or maps to something completely different, MySQL won't give access.

除非可以保证反向映射是稳定的,否则最好将IP地址用于MySQL中的远程访问帐户.

Unless you can guarantee that the reverse mapping is stable, it's best to use IP addresses for remote access accounts in MySQL.

这篇关于MySQL错误1045访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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