关于MySQL连接时报PROTOCOL_CONNECTION_LOST的处理

原因:默认或者设置的wait_timeout 时长过短导致
解决方案:
1、报错重连:判断报错code===’PROTOCOL_CONNECTION_LOST‘时重连
this.connection.on('error', err => {
    if (err.code === 'PROTOCOL_CONNECTION_LOST') {
        log.error('mysql error ===> PROTOCOL_CONNECTION_LOST')
        this.init()
    }
})
2、设置MySQL的interactive_timeout或wait_timeout
设置wait_timeout :
mysql> set global wait_timeout=864000;
Query OK, 0 rows affected (0.00 sec)
若无效,继续设置interactive_timeout:
mysql> set global interactive_timeout=864000;
Query OK, 0 rows affected (0.00 sec)
查看信息:
mysql> SHOW GLOBAL VARIABLES LIKE '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 120      |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 864000   |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 864000   |
+-----------------------------+----------+
13 rows in set (0.00 sec)

你可能感兴趣的:(数据库,mysql,android,数据库)