Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know what the error could be when I can connect to my MySQL server via localhost but not via AFAIK, these should be routed identically and no additional TCP layer should be created when using the IP.

$ mysql -u root -h localhost -D test # works
$ mysql -u root -h -D test # does not work
( does map to localhost/vice versa)

The table permissions are explicitly set to include both methods.

share|improve this question
up vote 3 down vote accepted

The MySQL client library overrides localhost to use a Unix socket instead of a TCP/IP connection to If you can connect to localhost but not, that suggests that it's either firewalled or not listening on

share|improve this answer

The manual at Connecting to the MySQL Server suggests using the following syntax :

shell> mysql --host=

The explanation is :

On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option. For example:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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