Cannot connect to local MySQL server (refers to version 5.5)
A MySQL client on Unix can connect to the mysqld server in two different ways:
- By using a Unix socket file to connect through a file in the file system (default
- by using TCP/IP, which connects through a port number. A Unix socket file connection is faster than TCP/IP, but can be used only when connecting to a server on the same computer.
A Unix socket file is used if you don’t specify a host name or if you specify the special host name
If the MySQL server is running on Windows, you can connect using TCP/IP. If the server is started with the
--enable-named-pipe option, you can also connect with named pipes if you run the client on the host where the server is running.
The name of the named pipe is
MySQL by default.
If you don’t give a host name when connecting to mysqld, a MySQL client first tries to connect to the named pipe. If that doesn’t work, it connects to the TCP/IP port. You can force the use of named pipes on Windows by using
. as the host name.
Make sure that the server has not been configured to ignore network connections or (if you are attempting to connect remotely) that it has not been configured to listen only locally on its network interfaces. If the server was started with
--skip-networking, it will not accept TCP/IP connections at all. If the server was started with
--bind-address=127.0.0.1, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections.
Check to make sure that there is no firewall blocking access to MySQL. Your firewall may be configured on the basis of the application being executed, or the port number used by MySQL for communication (3306 by default). Under Linux or Unix, check your IP tables (or similar) configuration to ensure that the port has not been blocked. Under Windows, applications such as ZoneAlarm or the Windows XP personal firewall may need to be configured not to block the MySQL port.
Unix socket file
- Someone has removed the Unix socket file that mysqld uses (
/tmp/mysql.sockby default). For example, you might have a cron job that removes old files from the
/tmpdirectory. You can always run mysqladmin version to check whether the Unix socket file that mysqladmin is trying to use really exists. The fix in this case is to change the cron job to not remove
mysql.sockor to place the socket file somewhere else. See Section C.5.4.5, “How to Protect or Change the MySQL Unix Socket File”.
- You have started the mysqld server with the
--socket=/path/to/socketoption, but forgotten to tell client programs the new name of the socket file. If you change the socket path name for the server, you must also notify the MySQL clients. You can do this by providing the same
--socketoption when you run client programs. You also need to ensure that clients have permission to access the
mysql.sockfile. To find out where the socket file is, you can do:
netstat -ln | grep mysql
- If the server is running on the local host, try using mysqladmin -h localhost variables to connect using the Unix socket file. Verify the TCP/IP port number that the server is configured to listen to (it is the value of the