I get a can't connect through this socket once per day.

Is this datadir correct?:

[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock

Aborted connection 1270592 to db: 'leechprotect' user: 'leechprotect' host: 'localhost' (Got timeout reading communication packets)


PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) in wp-includes/wp-db.php on line 1037 

QUESTION: How to change the sql connect from "localhost" to 127.0.0.1 as recommended by many people online. Do I have to do that via bind-address?

link|improve this question

64% accept rate
2  
Does the 'outage' happen at the same time each day? Perhaps when a backup is run, logs are rotated or some other scheduled task is being executed? If so, then disable that task. – Zoredache Aug 6 '11 at 4:09
2  
What's the justification behind trying to change to 127.0.0.1? I can't imagine a situation where that would help you connect to the socket. – Shane Madden Aug 6 '11 at 4:15
Thanks Shane, that's true. The only problem is that right now I'm pretty clueless why I get that error that Mysql cant connect to the socket. – mashup Aug 6 '11 at 5:44
feedback

2 Answers

Find your PHP db config file and change $host from 'localhost' to 'localhost:/var/lib/mysql/mysql.sock'.

link|improve this answer
Quanta, what exactly does it? I already specified the path to the mysql.sock im my.cnf .. isn't that enough? – mashup Aug 6 '11 at 5:42
No, that's not enough. my.cnf is used by mysqld, PHP DB config by PHP scripts. – ivan_pozdeev Dec 11 '11 at 2:40
feedback

1) If the error always happens at the same time, see which cron jobs run at that time. Cron configuration files (crotabs) are /etc/crontab and /var/spool/cron/*; see man crontab for their format description.

2) Check MySQL error log (in Linux, it's typically /var/lib/mysql/*.err ) for anything that happens around the moment the error occurs.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.