ubuntu下mysql的8小时经典问题,即mysql的连接“隔夜失效”问题,当mysql的空闲连接超过8小时,会自动断开。
这里介绍一种方法,设置timeout。mysql的版本是5.6,ubuntu 14。
首先先看看是不是默认8小时
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| 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 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+-----------------------------+----------+
12 rows in set (0.00 sec)
可以看到wait_timeout是28800,即8小时(8*60*60);
下面进入设置root@ubuntu:/home# mysql -uroot -pmysql> set global wait_timeout=86400;
Query OK, 0 rows affected (0.00 sec)
mysql> set global interactive_timeout=86400;
Query OK, 0 rows affected (0.00 sec)mysql> exit
Bye
退出重新进入查看mysql> show global variables like "%timeout%";
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 86400 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| wait_timeout | 86400 |
+-----------------------------+----------+
12 rows in set (0.00 sec)
退出,重启mysqlroot@ubuntu:/home# /etc/init.d/mysql restartOK!这是在项目里面遇到的一个问题,记录方便日后查询
参考了这篇文章