My /etc/hosts file has 127.0.0.1 localhost
line. When I try to connect to MySQL with mysql -u root -h localhost -p
I get the ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
error. However, when I connect using 127.0.0.1, it works fine or using localhost
with --protocol=TCP
.
I read here that Unix treats host name localhost
special and uses socket file instead of TCP/IP. Is it possible to connect to MySQL with socket file via terminal to not allow connections via the network?