MySQL Error 1045 Access Denied

佐手、 提交于 2019-12-01 14:18:30

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.

<?php
/* Set Variables */
$host="127.0.0.1:3306";
$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());    
}
else
{
echo 'Success... ' . $mysqli->host_info . "\n";
$mysqli->close();
}

?>

First of all, add these braces in for your if/else statement. Second, try hardcoding the IP. I just ran this with an IP set to a variable (didnt work) and then I hardcoded it, worked just fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!