Can't log in to MySQL - Access denied for user 'foobar'@'localhost' (using password: NO)


From shell, I am able to log in to mysql using both root and my custom mysql user (let’s call it ‘foobar’). However, I can’t log in via any external or local-based method such as phpMyAdmin, adminer, HeidiSQL, etc.

I see no errors in access.log nor error.log, but the error in the above programs seems to be of the 1045 type (Access denied for user ‘foobar’@‘localhost’ (using password: NO)). If it makes any difference, I am still using the IP via http, not domain name with https as my server is not yet production ready.

Could someone kindly point me to information on where I could try to figure out why this might be happening please?

Thank you


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


This is interesting. I could see a clear reason for HeidiSQL, and maybe that leads to the reason for the others. I assume phpMyAdmin and Adminer are set up on the server while HeidiSQL is run remotely. If they’re all three remote, then my idea makes sense across all of them.

When you create a user in MySQL, you define a host. If you do not define a host, it defaults to localhost. This means that all users are “user@ip” and by default “user@localhost.” So when you try to log in externally, you’re not just logging in as “user” but as “user@yourexternalip” instead.

Creating a remote user works like this from the shell:

GRANT ALL PRIVILEGES ON database.* TO 'username'@'ipaddress' IDENTIFIED BY 'password';

To connect remotely, ipaddress should be your external IP as found here: