緣由1. MySQL 服務宕了
判斷是不是屬于這個緣由的方法很簡單,履行以下命令,查看mysql的運行時長
$ mysql -uroot -p -e "show global status like 'uptime';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Uptime | 68928 |
+---------------+-------+
1 row in set (0.04 sec)
或查看MySQL的報錯日志,看看有無重啟的信息
$ tail /var/log/mysql/error.log
130101 22:22:30 InnoDB: Initializing buffer pool, size = 256.0M
130101 22:22:30 InnoDB: Completed initialization of buffer pool
130101 22:22:30 InnoDB: highest supported file format is Barracuda.
130101 22:22:30 InnoDB: 1.1.8 started; log sequence number 63444325509
130101 22:22:30 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
130101 22:22:30 [Note] - '127.0.0.1' resolves to '127.0.0.1';
130101 22:22:30 [Note] Server socket created on IP: '127.0.0.1'.
130101 22:22:30 [Note] Event Scheduler: Loaded 0 events
130101 22:22:30 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.28-cll' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
如果uptime數(shù)值很大,表明mysql服務運行了很久了。說明最近服務沒有重啟過。
如果日志沒有相干信息,也表名mysql服務最近沒有重啟過,可以繼續(xù)檢查下面幾項內(nèi)容。
2. 連接超時
如果程序使用的是長連接,則這類情況的可能性會比較大。
即,某個長連接很久沒有新的要求發(fā)起,到達了server真?zhèn)€timeout,被server強行關(guān)閉。
爾后再通過這個connection發(fā)起查詢的時候,就會報錯server has gone away
$ mysql -uroot -p -e "show global variables like '%timeout';"
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 30 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+----------------------------+----------+
mysql> SET SESSION wait_timeout=5;
## Wait 10 seconds
mysql> SELECT NOW();
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 132361
Current database: *** NONE ***
+---------------------+
| NOW() |
+---------------------+
| 2013-01-02 11:31:15 |
+---------------------+
1 row in set (0.00 sec)
3. 進程在server端被主動kill
這類情況和情況2相似,只是發(fā)起者是DBA或其他job。發(fā)現(xiàn)有長時間的慢查詢履行kill xxx致使。
$ mysql -uroot -p -e "show global status like 'com_kill'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_kill | 0 |
+---------------+-------+
4. Your SQL statement was too large.
當查詢的結(jié)果集超過 max_allowed_packet 也會出現(xiàn)這樣的報錯。定位方法是打出相干報錯的語句。
用select * into outfile 的方式導出到文件,查看文件大小是不是超過 max_allowed_packet ,如果超過則需要調(diào)劑參數(shù),或優(yōu)化語句。
mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)
修改參數(shù):
mysql> set global max_allowed_packet=1024*1024*16;
mysql> show global variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
參考: http://www.lai18.com/content/319554.html
上一篇 文件夾權(quán)限恢復步驟
下一篇 初識三層架構(gòu)