MySQL 的wait_timeout参数

下文描述了mysql的wait_timeout参数配置注意事项。简单的来讲要注意连接的程序用的是什么,是有状态的(如java,.net等)还是没状态的(如php,python等),有状态的wait_timeout连接时间要长(值范围60-259200),无状态的连接时间要短。mysql默认值是8小时。interactive_timeout(值范围10-86400)是用在shell交互时的超时时间。

其实很多性能优化的指导,都是如果无状态化。如缓存,静态化,轮循,分布式等,无状态很受欢迎。

 

Locate the timeout configuration and adjust it to fit your server.

wait_timeout = 28800
interactive_timeout = 28800
  • The interactive timeout does not affect any web application connections. A high interactive_timeout but a low wait_timeout is normal and is the best practice.

  • Choose a reasonable wait_timeout value. Stateless PHP environments do well with a 60 second timeout or less. Stateful applications that use a connection pool (Java, .NET, etc.) will need to adjust wait_timeout to match their connection pool settings. The default 8 hours (wait_timeout = 28800) works well with properly configured connection pools.

  • Configure the wait_timeout to be slightly longer than the application connection pool’s expected connection lifetime. This is a good safety check.

  • Consider changing the wait_timeout value online. This does not require a MySQL restart, and the wait_timeout can be adjusted in the running server without incurring downtime. You would issue set global wait_timeout=60 and any new sessions created would inherit this value. Be sure to preserve the setting in my.cnf. Any existing connections will need to hit the old value of wait_timeout if the application abandoned the connection. If you do have reporting jobs that will do longer local processing while in a transaction, you might consider having such jobs issue set session wait_timeout=3600 upon connecting.

转载于:https://my.oschina.net/swingcoder/blog/1518133

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值