General error: 2006 MySQL server has gone away
- 错误原因
- 制造错误
- 解决办法
- 最新办法
错误原因
Mysql has gone away
- MySQL 服务宕了
- mysql连接超时 show global variables like ‘%timeout’;
- mysql请求链接进程被主动kill show global status like ‘com_kill’;
- Your SQL statement was too large. show global variables like ‘max_allowed_packet’;
制造错误
造一个表
-- ----------------------------
-- Table structure for t_biubiu
-- ----------------------------
DROP TABLE IF EXISTS `t_biubiu`;
CREATE TABLE `t_biubiu` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`value` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
然后造一个程序
public function actionInsert(){
Biubiu::model()->findAll();
$result = Yii::app()->db->createCommand("show global variables like '%timeout'")->queryAll();
self::show_vars($result);
for($index = 1 ;$index< 10;$index++){
$model_ = new Biubiu();
$model_->value = "insert".$index;
if($index == 8){
sleep(31);
}
$model_->save();
}
$model = new Biubiu();
$model->value = "insert4";
$model->save();
}
设置你的MYSQL的wait_timeout = 30,interactive_timeout也要设置,否则不生效
执行的时候就会抛异常:
exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away. The SQL statement executed was: INSERT INTO `t_biubiu` (`value`