Error while loging to mysql

Asked by Giridhari

While loging to mysql following error comes
"Could not connect to host 'localhost'.
MySQL Error Nr. 2002
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

kindly help me to solve the problem.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
A. Denton (aquina) said :
#1

Is the file '/var/run/mysqld/mysqld.sock' present? - DO NOT CREATE IT BY HAND!

Maybe you try the following (enter in your shell):
1] $ locate mysql | grep "\.sock"
2] $ mysql-query-browser
       --> Connect -> Advanced Options -> Connect using socket file -> type (a) result

In case it doesn't help try this (serversupportforum.de):

Here are some reasons for the occurrence of the Can not connect to local MySQL server error:

* mysqld is not running.

* You drive on a system that uses MIT-pthreads. If you drive on a system that does not have native threads, mysqld uses the MIT-pthreads package. See Section 3.2.2, "Operating Systems Supported by MySQL Community Server". Not all MIT-pthreads versions support Unix sockets, however. On a system without socket support, you must always explicitly specify hostname when you connect to the server. Use this command to connect to the server to check:
         shell> mysqladmin-h `hostname` version

* Someone has the Unix socket removed the mysqld uses (default / tmp / mysqld.sock). Perhaps there is a cron job, which removes the MySQL socket (for example, a job that the old files from the / tmp directory removed). You can run mysqladmin version and check that the socket mysqladmin is trying to use actually exists. The solution in this case is the cron job to change so that it can not be removed or mysqld.sock socket at the other place to place. See Section A.4.5, "How the MySQL Socket File / tmp / mysql.sock Protect or Change."

* You have the mysqld server with the - socket = / path / to / socket option. If the socket pathname for the server, you must also specify the MySQL clients accordingly. You can do it by selecting the socket path as an argument to the client over. See Section A.4.5, "How the MySQL Socket File / tmp / mysql.sock Protect or Change."

* You are using Linux and one thread has died (core dump). In this case you must give the other mysqld thread kill (for example, with the mysql_zap script) before you create a new MySQL server can start. See Section A.4.1, "What to Do If MySQL Keeps Crashing".

* Maybe you have not read and write permissions for either the directory in which the socket file, or no authorization for the socket file itself In this case you can either use the Authorization for the file and / or the list or change mysqld restart, so he uses a directory to which you have access to.

If you get the error Can not connect to MySQL server on ein_hostname received, you can try to figure out why the problem:

* Verify that the server is started up by typing telnet ihr_hostname tcp-ip-port-number and run a few times by pressing the Enter key (RETURN) button. When it comes to this port a running MySQL server, you should receive a reply, the version number of the server. If you notice an error like telnet: Unable to connect to remote host: Connection refused obtained, there is no port in the current server.

* Try to deal with the mysqld daemon on the local machine to connect and check the TCP / IP port, according to the mysqld configuration should use (variable port) with mysqladmin variables.

*Check that your mysqld server was not started by using the - skip-networking option.

Revision history for this message
A. Denton (aquina) said :
#2

Is the problem yet solved?

Revision history for this message
A. Denton (aquina) said :
#3

Unfortunately I do not have the powers to change the state of this question to SOLVED, EXPIRED or INVALID. Someone here at Launchpad either grant me that permission or simply apply the change in state to this question, please.

Can you help with this problem?

Provide an answer of your own, or ask Giridhari for more information if necessary.

To post a message you must log in.