Lost connection to MySQL server during query
Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in /var/www/localhost/htdocs/xyz.php on line 32
Can not connect to the database. Lost connection to MySQL server during query
I can get rid of this error by setting register_globals on in my php.ini but I want to know if there is a real fix without doing this.
Here is a sample of what I am doing in my xyz.php file to connect
define('LOC','LOC');
define('USER', 'USER');
define('PASS', 'PASS');
define('DB', 'DB');
mysql_connect(LOC,USER,PASS)
or die("Can not connect to the database. " . mysql_error());
mysqlselectdb(DB)
or die("Can not select database. " . mysql_error());
24 Replies
@fifo:
define('LOC','LOC');
define('USER', 'USER');
define('PASS', 'PASS');
define('DB', 'DB');
mysql_connect(LOC,USER,PASS)
or die("Can not connect to the database. " . mysql_error());
mysqlselectdb(DB)
or die("Can not select database. " . mysql_error());
I normally have something like:
$LOC = "LOC";
$USER = "USER";
$PASS = "PASS";
$DB = "DB";
$link = mysql_connect($LOC, $USER, $PASS)
or die("Can't Connect");
mysqlselectdb($DB, $link) or die("Can't Connect");
That kind of setup has always worked for me.
I't does work however about 25 % of the times I am accessing the site I get that error. But the other 75% it works fine…
Let me check if I have the $link variable in there I might and I will get back as soon as I have access to my files..
mysqlselectdb($DB, $link) or die("Can't Connect");
$link = mysql_connect($LOC, $USER, $PASS)
rather than just
mysql_connect($LOC, $USER, $PASS)
and also having
mysql_select_db($DB, $link)
helps because it explicitly uses that link to connect that way so you are less likely to lose your connection. I'm not sure if it actually makes a difference as I have never had any problems, perhaps it is a problem with your mysql server, this however is just speculation on my part but maybe you should check your apache and MySQL logs.
Either way thanks for the help im going to try that out and let you know how it goes…
Can I pick your brain for any more Ideas?
Good Luck
6384: | | | | | | | | exit: ptr: 0x8cc8178
T@16384: | | | | | | | <_mymalloc
T@16384: | | | | | | | >_myfree
T@16384: | | | | | | | | enter: ptr: 0x8cc18b0
T@16384: | | | | | | | <_myfree
T@16384: | | | | | | <_myrealloc
T@16384: | | | | | <miextra
T@16384: | | | |
T@16384: | | |
T@16384: | | | >freeroot
T@16384: | | | | enter: root: 0x8ccdfcc flags: 1
T@16384: | | |
T@16384: | |
T@16384: | | >do_command
T@16384: | | | >vioisblocking
T@16384: | | | | exit: 0
T@16384: | | |
T@16384: | | | >vio_read
T@16384: | | | | enter: sd=16, buf=0x8ccf388, size=4
T@16384: | | | | vio_error: Got error 11 during read
T@16384: | | | | exit: -1
T@16384: | | | <vioread
T@16384: | | | info: vioread returned -1, errno: 11
T@16384: | | | >thr_alarm
T@16384: | | | | enter: thread: T@16384 sec: 28800
T@16384: | | | | info: reschedule
T@131081: | >process_alarm
T@131081: | | info: sig: 14 active alarms: 1
T@131081: |
T@16384: | | |
T@16384: | | | >vio_blocking
T@16384: | | | | enter: setblockingmode: 1 old_mode: 0
T@16384: | | | | exit: 0
T@16384: | | | <vioblocking
T@16384: | | | >vioread
T@16384: | | | | enter: sd=16, buf=0x8ccf388, size=4
vio_read
T@16384: | | | | enter: sd=16, buf=0x8ccf388, size=4
T@16384: | | | | vio_error: Got error 11 during read
T@16384: | | | | exit: -1
mysqld.err doesnt say much at least nothing about an error:q!
InnoDB: !!!!!!!!!!!!!! UNIV_DEBUG switched on !!!!!!!!!!!!!!!
060412 18:22:28 InnoDB: Started; log sequence number 0 47123
/usr/sbin/mysqld: ready for connections.
Version: '4.1.14-debug-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 Gentoo Linux mysql-4.1.14-r1
mysql.err says nothing same for mysql.log and mysqld.log
this is what I get when I try to run status on mysqladmin
mysqladmin -i 5 -r status
Uptime: 1295 Threads: 2 Questions: 1987 Slow queries: 0 Opens: 134 Flush tables: 1 Open tables: 43 Queries per second avg: 1.534 Memory in use: 17001K Max memory used: 19577K
Uptime: 1300 Threads: 4 Questions: 2049 Slow queries: 0 Opens: 134 Flush tables: 1 Open tables: 43 Queries per second avg: 1.576 Memory in use: 17117K Max memory used: 19577K
Uptime: 1305 Threads: 2 Questions: 2115 Slow queries: 0 Opens: 134 Flush tables: 1 Open tables: 43 Queries per second avg: 1.621 Memory in use: 17001K Max memory used: 19577K
Uptime: 1310 Threads: 4 Questions: 2184 Slow queries: 0 Opens: 134 Flush tables: 1 Open tables: 43 Queries per second avg: 1.667 Memory in use: 17116K Max memory used: 19577K
Lost connection to MySQL server during query
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)blocking
alarm
alarm
read
isblocking
command
root
threadtables
threadtable
mysql.trace_mode = On
and this is what I got on my page. Why would this be happening?
Warning: Unknown: 1 result set(s) not freed. Use mysqlfreeresult to free result sets which were requested using mysql_query() in Unknown on line 0
is this just the current queries on the page? thats what it seems like to me… Should they be closed once the page is shown?
I wasn't releasing my result sets from my queries. like you saw in the warnings above. Im not sure why this would make mysql crash but it did. I thought the result sets automatically closed upon exit of the query or the page? Or even time out after a while.
Here was the solution
mysqlfreeresult("QUERY VARIABLE HERE");
?>
Just a thought…
-Chris
this is all I get but its on acouple of tables…
did it a couple of times more and evretrything checks out ok
I have max media manager installed after getting errors so I know its not because of this and I get this whenever I try to see statistics.
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 35 bytes) in /var/www/localhost/htdocs/xyz/max-v0.3.21-alpha/lib/pear/HTML/Template/Flexy/Tokenizer.php on line 1197
Havent had mysql crash today yet but I dont think the two problems were related.
Development machine has same setup gentoo os and mysql versions are identical.
is this a bad setup for a production server?
Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode On On
mysql.trace_mode I just turned this off
I can't pinpoint it though because I un-merged mysql removed all databases and re-emerged mysql then restored my databases.
everything was running until host 45 just stopped responding at around 7:12 EST.