Question

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

Hello,

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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Greetings!

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: https://ifconfig.me/

Jarland