MYSQL server ip does not work the same way as localhost -
lets ip of our server 55.555.555.55. lets have mysql user 'user'@'localhost'
so then, why return permission error
$mysql_server = "55.555.555.55"; $mysql_user = ""; $mysql_password = ""; $mysql_db = ""; $mysqli = new mysqli($mysql_server, $mysql_user, $mysql_password, $mysql_db); if ($mysqli->connect_errno) { printf("connection failed: %s \n", $mysqli->connect_error); exit(); } $mysqli->set_charset("utf8");
but not
$mysql_server = "localhost"; $mysql_user = ""; $mysql_password = ""; $mysql_db = ""; $mysqli = new mysqli($mysql_server, $mysql_user, $mysql_password, $mysql_db); if ($mysqli->connect_errno) { printf("connection failed: %s \n", $mysqli->connect_error); exit(); } $mysqli->set_charset("utf8");
isn't 55.555.555.55 , localhost same thing? shouldn't issue.
no, localhost
treated mysql bypass tcp/ip. uses unix socket. , need 2 rows in mysql.user
privileges table authorize these 2 access methods, if username , password same.
the wildcard '%'
matches ip address or hostname, not match localhost. may counter-intuitive, it's way mysql works.
this explained here: http://dev.mysql.com/doc/refman/5.6/en/connecting.html
Comments
Post a Comment