---
title: "mysql timeout问题"
author: "bravejack"
date: "2010-06-28T11:13:16Z"
tags: []
categories: ["数据库"]
slug: "mysql-timeout"
draft: false
lastmod: "2010-06-28T11:13:16Z"
id: 700677
url: "https://bravejack.iteye.com/blog/700677"
---

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,与前台连接池配合

### [](http://alixiaobai.iteye.com/blog/587455)