“MySQL server has gone away”的重現方法(PHP) 如果想調試“MySQL server has gone away”的問題,可以這樣重現: 修改配置文件: [html] sudo vi /etc/mysql/my.cnf 做如下修改: [html] [mysqld] wait_timeout = 30 interactive_timeout = 30 重啟服務: [html] sudo /etc/init.d/mysql restart 編寫如下php腳本 [php] <?php $link = mysql_connect('127.0.0.1', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; sleep(31); $result = mysql_query('show variables;'); if (!$result) { die('Invalid query: ' . mysql_error()); } while ($row = mysql_fetch_assoc($result)) { var_dump($row); } mysql_free_result($result); mysql_close($link); ?> 執行: [plain] $ php mysql.php Connected successfully Invalid query: MySQL server has gone away 或者在命令行下也可以看到這個錯誤了: [plain] mysql> select variables like '%timeout'; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 40 Current database: *** NONE ***