0

Im in Ubuntu 16.04.5 LTS

if I do mysql -h localhost -u root I can connect with no issues. But if I do, mysql -h 127.0.0.1 -u root I get:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

How do I fix this?

  • What is the rest of the message? – Michael Hampton Jun 14 at 22:05
  • Perhaps mysql is only listening on IPv6 - check what address localhost resolves to. – Jens Ehrich Jun 15 at 0:09
1

MySQL considers 127.0.0.0/8 addresses to be different from localhost so when creating users if you specify one you need to connect using that one reference.

Additionally, some MySQL connectors will use a socket when connecting to localhost but use TCP/IP when connecting to 127.0.0.1

Finally, one of the more recent differences is if localhost is used socket authentication is done - if you are logged in as the root user, you can be logged in to MySQL w/o a password. Played silly buggers with some backup scripts I wanted to run via cron when I first found that one...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.