[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Can't connect to [local] MySQL server
Error
A MySQL client on Unix can connect to the mysqld
server in two
different ways: Unix socket files, which connect through a file in the file
system (default `/tmp/mysqld.sock') or TCP/IP, which connects
through a port number. Unix socket files are faster than TCP/IP but can only
be used when connecting to a server on the same computer. Unix socket files
are used if you don't specify a hostname or if you specify the special
hostname localhost
.
On Windows, if the mysqld
server is running on 9x/Me, you can
connect only via TCP/IP. If the server is running on NT/2000/XP and
mysqld is started with --enable-named-pipe
, you
can also connect with named pipes. The name of the named pipe is MySQL.
If you don't give a hostname when connecting to mysqld
, a MySQL
client will first try to connect to the named pipe, and if this doesn't
work it will connect to the TCP/IP port. You can force the use of named
pipes on Windows by using .
as the hostname.
The error (2002) Can't connect to ...
normally means that there
isn't a MySQL server running on the system or that you are
using a wrong socket file or TCP/IP port when trying to connect to the
mysqld
server.
Start by checking (using ps
or the task manager on Windows) that
there is a process running named mysqld
on your server! If there
isn't any mysqld
process, you should start one. See section 2.4.2.3 Starting and Troubleshooting the MySQL Server.
If a mysqld
process is running, you can check the server by
trying these different connections (the port number and socket pathname
might be different in your setup):
shell> mysqladmin version shell> mysqladmin variables shell> mysqladmin -h `hostname` version variables shell> mysqladmin -h `hostname` --port=3306 version shell> mysqladmin -h 'ip for your host' version shell> mysqladmin --protocol=socket --socket=/tmp/mysql.sock version |
Note the use of backquotes rather than forward quotes with the hostname
command; these cause the output of hostname
(that is, the current
hostname) to be substituted into the mysqladmin
command.
Here are some reasons the Can't connect to local MySQL server
error might occur:
mysqld
is not running.
mysqld
uses the MIT-pthreads package. See section 2.1.1 Operating Systems Supported by MySQL. However,
not all MIT-pthreads versions support Unix socket files. On a system
without sockets support you must always specify the hostname explicitly
when connecting to the server. Try using this command to check the
connection to the server:
shell> mysqladmin -h `hostname` version |
mysqld
uses (default
`/tmp/mysqld.sock'). You might have a cron
job that removes
the MySQL socket (for example, a job that removes old files
from the `/tmp' directory). You can always run mysqladmin
version
and check that the socket mysqladmin
is trying to use
really exists. The fix in this case is to change the cron
job to
not remove `mysqld.sock' or to place the socket somewhere else.
See section A.4.5 How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'.
mysqld
server with
the --socket=/path/to/socket
option. If you change the socket
pathname for the server, you must also notify the MySQL clients
about the new path. You can do this by providing the socket path
as an argument to the client. See section A.4.5 How to Protect or Change the MySQL Socket File `/tmp/mysql.sock'.
mysqld
threads (for example, with the
mysql_zap
script before you can start a new MySQL
server. See section A.4.1 What To Do If MySQL Keeps Crashing.
mysqld
so that it uses a directory that you can access.
If you get the error message Can't connect to MySQL server on
some_hostname
, you can try the following things to find out what the
problem is:
telnet your-host-name
tcp-ip-port-number
and press Enter a couple of times. If there
is a MySQL server running on this port you should get a
responses that includes the version number of the running MySQL
server. If you get an error like telnet: Unable to connect to
remote host: Connection refused
, then there is no server running on the
given port.
mysqld
daemon on the local machine and check
the TCP/IP port that mysqld
it's configured to use (variable port
) with
mysqladmin variables
.
mysqld
server is not started with the
--skip-networking
option.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |