tags:

views:

34

answers:

4

I have been creating a new website and am new to all this. Every so often, I get the following error and after a while, it goes away and the website comes back?

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11) in /home/gamepla3/public_html/include/database.php on line 16 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (11)

Could anyone shed any light on the problem I have here? Sorry if the question is vague, I possibly don't understand what you would need to know. Thanks

A: 

You seem to have a problem with your MySQL server. Next time, check if you can connect to your database with your MySQL client, and if not, check your MySQL logs.

greg0ire
It has just come back online, but I went through phpmyadmin before and got the following error,The server is not responding (or the local MySQL server's socket is not correctly configured)
Luke
Then check your MySQL logs in /var/log/mysql
greg0ire
A: 

Can you show the code?

blacktooth
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
Luke
Are you closing your connection? If not, try using mysql_pconnect()
blacktooth
@blacktooth: non-persistent connections are automatically closed (unless you have a **very** old mysql client running on a threaded webserver).
symcbean
A: 

You need to submit operating system, so the diagnostic test for can be thought of.

1. Check if the daemon for MySQL (you shoudl find mysqld in your process list) is running.
2. What is the port no on which the daemon is operating, have you installed something else which is requiring the same port no.
Chaitannya
It's coming from a hosting company, is it still possible to check these things?
Luke
A: 

If it works sometimes and not others (without intervention) then the primary cause is not your code.

You need to verify:

1) That the database was running at the time of the outage

2) That the max connections had not been exceeded

Probably the best way to go about this would be to write your own error handler which could check the process list and the permissions on the socket file at the time of an outage - and make sure the mysql error logging is set up and configured correctly.

C.

symcbean