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 -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? Jun 14, 2019 at 22:05
  • Perhaps mysql is only listening on IPv6 - check what address localhost resolves to. Jun 15, 2019 at 0:09

1 Answer 1


MySQL considers 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

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...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .