2011-11-24 11 views
5

Sto cercando di far fronte all'errore di MySQL MySQL server has gone away in un django env.Intenzionalmente ottenere un errore "Il server MySQL è andato via"

La soluzione rapida era impostare il valore globale wait_timeout MySQL variable su un valore enorme, ma a lungo termine questo si sarebbe accumulato su molte connessioni aperte.

Ho pensato di ottenere la variabile wait_timeout e di eseguire il polling del server a intervalli più piccoli. Dopo aver implementato questo ho provato a testarlo ma non riesco a ottenere l'errore.

I set global wait_timeout=15 e anche set global interactive_timeout=15 ma la connessione si rifiuta di scomparire. Sono sicuro che sto interrogando il database a intervalli più ampi di 15 secondi.

Quale potrebbe essere la causa per non essere in grado di ricreare questo errore?

+2

+1 per voler verificare le condizioni di errore. – vidstige

risposta

4

Esegui sotto la sceneggiatura sporca e veloce e testa il tuo progetto django o qualsiasi altra cosa. Penso che questo non sia un approccio elegante, ma funziona bene.

<?php 
mysql_connect("127.0.0.1", "id", "pw"); // should be changed to yours 
while(1) 
{ 
    $r = mysql_query("SHOW PROCESSLIST"); 
    while($d = mysql_fetch_row($r)) 
    { 
     if($d[7] != "SHOW PROCESSLIST") 
     { 
      mysql_query("KILL ". $d[0]); 
      echo($d[0]." was killed.\n"); 
     } 
    } 
} 
?> 

Ed ecco il risultato.

mysql> select * from foo; 
ERROR 2006 (HY000): MySQL server has gone away 
No connection. Trying to reconnect... 
Connection id: 337 
Current database: test 

ERROR 2006 (HY000): MySQL server has gone away 
No connection. Trying to reconnect... 
Connection id: 338 
Current database: test 

ERROR 2006 (HY000): MySQL server has gone away 
mysql> 
Problemi correlati