解决 MySQL server has gone away

#应用程序(比如PHP)长时间的执行批量的MYSQL语句。执行一个SQL,但SQL语句过大或者语
#句中含有BLOB或者longblob字段。比如,图片数据的处理。都容易引起MySQL server has gone away。


'''
mysql> show variables like '%wait_timeout%' ;
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| innodb_lock_wait_timeout | 50    | 
| table_lock_wait_timeout  | 50    | 
| wait_timeout             | 28800 | 
+--------------------------+-------+

mysql> show variables like '%max_allowed_packet%';
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
'''
cur.execute('set global innodb_lock_wait_timeout = 2880000')    # 语句执行间断时间
cur.execute('set global wait_timeout = 288000')                 # 最大等待时间
cur.execute('set global max_allowed_packet = 2880000')          # 上传大小

你可能感兴趣的:(sql,mysql,PHP,SQL Server,python)