질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

긴급 mysql 관련입니다

작성자 정보

  • 이충구 작성
  • 작성일

컨텐츠 정보

본문

A.2.3 Can't connect to [local] MySQL server Error

A MySQL client on Unix can connect to the mysqld server in two different ways: Unix sockets, which connect through a file in the file system (default `/tmp/mysqld.sock') or TCP/IP, which connects through a port number. Unix sockets are faster than TCP/IP but can only be used when connecting to a server on the same computer. Unix sockets 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 Problems Starting 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, of course):

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

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.
  • You are running on a system that uses MIT-pthreads. If you are running on a system that doesn't have native threads, mysqld uses the MIT-pthreads package. See section 2.2.2 Operating Systems Supported by MySQL. However, not all MIT-pthreads versions support Unix sockets. 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
    
  • Someone has removed the Unix socket that 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'.
  • You have started the 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'.
  • You are using Linux and one thread has died (core dumped). In this case you must kill the other 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.
  • You may not have read and write privilege to either the directory that holds the socket file or privilege to the socket file itself. In this case you have to either change the privilege for the directory / file or restart 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 :

  • Check if the server is up by doing 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.
  • Try connecting to the mysqld daemon on the local machine and check the TCP/IP port that mysqld it's configured to use (variable port) with mysqladmin variables.
  • Check that your mysqld server is not started with the --skip-networking option.

Comments:

Linda Wright: 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.

George Stavroulakis: 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...

Amy Law: 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:mysqlin>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:mysqlin>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

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,074 명
  • 현재 강좌수 :  35,995 개
  • 현재 접속자 :  550 명