日期:2014-05-16  浏览次数:20691 次

mysql timeout问题

1,set global wait_timeout=10;vs set wait_timeout=10; no need restart mysql

2,On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVE connect option to mysql_real_connect()).

3,如果你没有修改过MySQL 的配置,缺省情况下,wait_timeout的 初始值是28800。

4,wait_timeout过大有弊端,其体现就是MySQL里大量的SLEEP进程无法及时释放,拖累系统 性能 ,不过也不能把这个指设置 的过小,否则你可能会遭遇到“MySQL has gone away”之类的问题,通常来说,我觉得把wait_timeout设置为10是个不错的选择,但某些情况下可能也会出问题,比如说有一个CRON脚本 ,其中两次SQL查询的间隔时间大于10秒的话,那 么这个设置就有问题了(当然,这也不是不能解决 的问题,你可以在程序 里时不时mysql _ping一下,以便服务器 知道你还活着,重新计算wait_timeout 时间):也可修改my.cnf

5,与前台连接池配合