Search the MySQL manual:
MySQL Manual

Buy this Reference Manual in softcover from Barnes & Noble!

/ / Up / Table of Contents

A.2.3 Ошибка Can't connect to [local] MySQL server

Клиент MySQL на Unix может соединиться с сервером mysqld двумя различными способами: используя либо Unix-сокеты, когда соединение происходит через файл в файловой системе (по умолчанию `/tmp/mysqld.sock'), либо TCP/IP с соединением через номер порта. Unix-сокеты обеспечивают большую скорость, чем TCP/IP, но могут применяться только при соединении с сервером на том же компьютере. Unix-сокеты используются, если не задано имя хоста или если задано специальное имя localhost.

В Windows, если сервер mysqld выполняется в 9x/Me, возможно соединение только через TCP/IP. Если сервер работает на NT/2000/XP и mysqld запущен с --enable-named-pipe, то можно также устанавливать соединение с помощью именованных каналов. Имя именованного канала - MySQL. Если имя хоста не указано при соединении с mysqld, то клиент MySQL сначала попробует подключиться к именованному каналу, а если этого сделать не удастся, то к порту TCP/IP. Можно предписать использование именованных каналов в Windows, используя . в качестве имени хоста.

Ошибка (2002) Can't connect to ... обычно говорит о том, что MySQL не запущен на данной системе или что при попытке соединиться с сервером mysqld используется неверный сокет-файл или порт TCP/IP.

Для начала проверьте (с помощью ps или диспетчера задач в Windows), выполняется ли на сервере процесс с именем mysqld! Если процесса mysqld нет, то его необходимо запустить (see section 2.4.2 Проблемы при запуске сервера MySQL).

Если процесс mysqld выполняется, то можно проверить сервер, пробуя использовать следующие различные соединения (конечно, номер порта и путь сокета для вашей конфигурации могут быть другими):

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 --socket=/tmp/mysql.sock version

Обратите внимание на то, что для hostname используются обратные кавычки вместо прямых; это задает подстановку вывода hostname (т.е. текущего имени хоста) в команду mysqladmin.

Ниже приводится несколько причин, которые могут вызывать ошибку Can't connect to local MySQL server:

Если получено сообщение об ошибке Can't connect to MySQL server on some_hostname, то чтобы выяснить, в чем проблема, можно попробовать выполнить следующие действия:

User Comments

Posted by on Tuesday August 13 2002, @7:17pm [Delete] [Edit]

If you have just done a manual modification of
mysql db permissions or a source load into a
database which alters permissions to allow remote
connections etc., you will need to do a "mysqladmin
reload" on the database before the changes will take
effect. This is particularly important when configuring
remote access permissions - connection attempts
will not be allowed using new permissions even
though the mysql records look perfect.
Remembering to use the mysqladmin reload
command can save a lot of needless debugging.

Posted by on Sunday September 22 2002, @2:23pm [Delete] [Edit]

For Win9x/Me/2000/XP platform: I had an error
description like "ERROR 2003: Can't connect to
MySQL at 'localhost' (10063)" but could not get rid
of with the usual ways. The mysqld-nt service was
running but I had no connection. The problem was
that I had accidentally erased my "share" directory
and the mysqld-nt service was up but NOT running
as it was trying to find the share directory. Since it
was not running, it could NOT respond to socket
requests, hence the error with the 10063 code. To
sum up, if you have this error check out if all the
folders are in place...

Posted by on Tuesday October 1 2002, @10:38pm [Delete] [Edit]

I had the problem with "*ERROR 2003: Can't
connect to MySQL server on 'localhost' (10061)*"
and here is how I resolved the issue. I thought I
would share my solution with you...

1. Uninstalled mysql (I guess my first installation
was corrupted).

2. c:\mysql\bin>mysqld-nt.exe --install

3. Reboot

4. Now, check the task manager and mysqld-nt.exe
should be running at the background. If not, there is
something wrong with the install -- I believe
it was my problem.

5. C:\mysql\bin>mysql -u root mysql

6. mysql> set password for
root@localhost=PASSWORD("funfun");

7. mysql> update user set password=PASSWORD
("funfun") where user='root';

8. mysql> flush privileges;

Note that funfun is my password

Posted by Mike Discenza on Tuesday November 26 2002, @11:29am [Delete] [Edit]

I've received "ERROR 2003: Cannot connect to MySQL
server on '' (111)" when the loopback
has multiple addresses configured. One address
for 127.0.0.1 and at least one other address. As
soon as the alias for the loopback was removed I
was able to connect. This happened on a RH7.3 server.

Posted by Siegfried LЖhr on Tuesday December 3 2002, @1:43am [Delete] [Edit]

By chance one has changed the
mysql_default_socket value in php.ini. It was set to
the document root path of my web server. This led
to error 2002 "Can't connect to local MySql server..."
After removing the value everything was fine again.

Posted by [name withheld] on Saturday March 1 2003, @3:41pm [Delete] [Edit]

Sometimes you just have to comment out "skip-networking" in /etc/mysql/my.cnf and restart mysql.

Posted by Raj Rossrakesh on Tuesday March 4 2003, @9:45pm [Delete] [Edit]

I was having probs when trying to setup mysql control centre on my windoze 2000 box. Iam getting this msg.....
[Mysql] ERROR 2013: Lost connection to MySQL server during query

MYSQL server running on Redhat 8
Shell> mysqladmin version
mysqladmin Ver 8.23 Distrib 3.23.52, for pc-linux-gnu on i686
Server version 3.23.52
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 4 min 52 sec

Threads: 1 Questions: 3 Slow queries: 0 Opens: 6 Flush tables: 1 Open tables: 0 Queries per second avg: 0.010


just the line
set-variable = thread_stack=256K
in my.cnf
restart MySQL server

don't forget to give access to hosts other then the localhost as well
grant all privileges on *.* to [email protected].% identified by 'dbpass';


Posted by Sergio Salgueiro on Wednesday March 5 2003, @11:35am [Delete] [Edit]

Usually, the /etc/my.cnf file points to /var/lib/mysql/mysql.sock for the socket file.

Changind the pointers to /tmp/mysql.sock will
make apache work.

Posted by on Saturday March 8 2003, @11:29pm [Delete] [Edit]

I'm trying to connect to a database running off a W2K server from my Linux 8.0. Both machines have mysql server installed and running properly. However when I type in the Linux box the command: mysql -h id_address -u user_name, I'd get this error message:
ERROR 2003: Can't connect to MySQL server on '63.202.128.121' (110)

This error won't happen if I connect from a W2K Professional workstation. Any idea why this happens?

Add your own comment.

Top / / / Up / Table of Contents