I have a problem with mysqli connection.

When I do it this way:

$link = mysqli_connect("localhost:3306", "admin_xxx", "password", "admin_xxx");

It's not working and gives error:

Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging error: Access denied for user 'admin_xxx'@'::1' (using password: YES)

But when I'm not using port, just:

$link = mysqli_connect("localhost", "admin_xxx", "password", "admin_xxx");

It works.

Where's a problem? It's third party script and I need to use PORT.

  • add correct user name – vikrant zilpe Dec 4 at 13: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. – vikrant zilpe Dec 4 at 13:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.