In order to replicate some script behavior on a test box I need to auth mysql with root via unix socket.

It works fine with sudo mysql, but when I do sudo mysql -h testhost I get:

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

I have added testhost to my hosts file localhost testhost

I have also updated mysql grants

    | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED VIA unix_socket USING '*59D9CEFB549F231CFA8634AC47153FD4F3CCC29F' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED VIA unix_socket USING '*59D9CEFB549F231CFA8634AC47153FD4F3CCC29F'

1 Answer 1


"Unix sockets" are not TCP/IP sockets. They are always limited to the current system only – it is not possible to connect to another system's socket over the network.

Because of that, the hostname localhost is special in MySQL and the client doesn't actually attempt to look up its IP address at all. And when you connect to it, you are not connecting to nor ::1 – you're actually connecting to /var/run/mysqld/mysqld.sock or some similar path.

If you want to imitate a network connection, run mysql -h or mysql -h ::1.

Network (TCP/IP) connections cannot use IDENTIFIED VIA unix_socket, because they do not transfer the client's UID (especially not in any security-sensitive way). They must use passwords, X.509 certificates, or GSSAPI.

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.