1

I have an application designed in mysql and php. Earlier this app was working fine. But now it is not. Its giving me an error :

***Failed to connect to MySQL: Can't connect to local MySQL server through socket 
'/var/lib/mysql/mysql.sock' (2)***

How can I resolve this error ?

The application is running on a redhat machine.

user3086014
  • 4,241
  • 5
  • 27
  • 56

4 Answers4

2

Does the directory "/var/lib/mysql" exist? also please check your mysql user (or better, mysql group) have writer permission. If so, please try re-starting mysql and see what happens

Mahesh
  • 872
  • 1
  • 10
  • 25
2

You must follow the below steps to debug the error:-

  1. start mysql engine.

  2. check below database connecting variable

    a. host name

    b. username

    c. password

    d. database name

  3. now check query for connecting with mysql.

  4. now check whether it's able to connect with database or not.

I think this will help You to resolve the problem. If it persists then let me know.

Ripa Saha
  • 2,532
  • 6
  • 27
  • 51
  • see the application has everything in place but cant access it – user3086014 Jan 08 '14 at 06:53
  • some errors are ofcourse there. otherwise why it's not connecting. You need to debug and find. We only suggest You the debugging steps for this problem. one thing also You can do , You can manually write a connection code for testing. – Ripa Saha Jan 08 '14 at 07:00
  • the application was working fine. it sometimes work fine sometimes not. It means that the code is correct. there is no prb in configuration and aplication – user3086014 Jan 08 '14 at 07:01
  • for connection what have You used? Persistent connection? – Ripa Saha Jan 08 '14 at 07:05
1

Reference link you may find the solution.According to the link it says:

Are you connecting to "localhost" or "127.0.0.1" ? I noticed that when you connect to "localhost" the socket connector is used, but when you connect to "127.0.0.1" the TCP/IP connector is used. You could try using "127.0.0.1" if the socket connector is not enabled/working.

Community
  • 1
  • 1
0

i think your mysql server is not running. Make sure your mysql server is running

use

# mysqladmin -u root -p status

to check status

if it is running , try to connect from command line. And execute some simple select statement from command line. If your are able to do that, make sure that username and password (used in command line) are used in your application too.

If your are application working sometime and sometime not, in that case make sure you are closing connections in your program after use.

Fathah Rehman P
  • 8,401
  • 4
  • 40
  • 42
  • the outputs is `Uptime: 161 Threads: 1 Questions: 67 Slow queries: 0 Opens: 25 Flush tables: 1 Open tables: 18 Queries per second avg: 0.416 ` – user3086014 Jan 08 '14 at 07:02
  • õutput : `Uptime: 62 Threads: 16 Questions: 177 Slow queries: 0 Opens: 20 Flush tables: 1 Open tables: 13 Queries per second avg: 2.854` – user3086014 Jan 08 '14 at 07:37
  • @user3086014 -try to connect from command line. And execute some simple select statement from command line. If your are able to do that, make sure that username and password (used in command line) are used in your application too. If your are application working sometime and sometime not, in that case make sure you are closing connections in your program after use. – Fathah Rehman P Jan 08 '14 at 07:41
  • i dont know whats the issue. fed up now :( – user3086014 Jan 08 '14 at 07:49
  • i am facing the issue today only ] – user3086014 Jan 08 '14 at 07:49
  • @user3086014- if you are not properly closing connections, at some point you will reach "max_connections" of mysql. And mysql won't allow further connections. I think this is what happening for you. And after some time, some connections will automatically close due to timeout. Then only you will be able to connect to mysql again. So make sure your application properly closing connections after user – Fathah Rehman P Jan 08 '14 at 08:07