error 1045 mysql,MySQL错误1045访问被拒绝

Good Morning,

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)

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.

Here's the code block:

/* 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?

Thanks,

Sid

解决方案

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.

For instance, if you do

GRANT blah ON *.* to user@somehost

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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值