How to Change the MySQL Timeout on a Server
2015-10-16 13:52
671 查看
A MySQL server timeout can occur for many reasons, but happens most often when a command is sent to MySQL over a closed connection. The connection could have been closed by the MySQL server because of an idle-timeout; however, in most cases it is caused by either an application bug, a network timeout issue (on a firewall, router, etc.), or due to the MySQL server restarting. Rarely does the
Follow these steps to resolve the issue:
Login to your server using SSH.
Edit
Locate the timeout configuration and adjust it to fit your server.
The interactive timeout does not affect any web application connections. A high
Choose a reasonable
Configure the
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.
Save the changes and exit the editor.
Restart MySQL to apply the changes as follows:
Once the restart completes, the new changes are applied.
wait_timeoutvalue cause the problem, and changing the value does not fix the problem. For cases where an application fails to close a connection it is no longer using, a low
wait_timeoutvalue can help to avoid hitting
max_connectionssimply due to “sleeping” idle connections that are not in a transaction and will not be reused.
Follow these steps to resolve the issue:
Login to your server using SSH.
Edit
my.cnf(the MySQL configuration file).
sudo vi /etc/my.cnf
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_timeoutbut a low
wait_timeoutis normal and is the best practice.
Choose a reasonable
wait_timeoutvalue. 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_timeoutto match their connection pool settings. The default 8 hours (
wait_timeout = 28800) works well with properly configured connection pools.
Configure the
wait_timeoutto 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.
Save the changes and exit the editor.
Restart MySQL to apply the changes as follows:
sudo /etc/init.d/mysql restart
Once the restart completes, the new changes are applied.
相关文章推荐
- MySQL中tinytext、text、mediumtext和longtext详解
- MySQL日期时间函数大全
- vs2013 ef,使用 MySQL来做数据库开发
- mysql 存储过程和存储函数
- mac下卸载mysql
- 免安装mysql的配置
- MYSQL 8 Hours Time out Problem
- MySQL: Create Master - Slave Servers
- MySQL错误ERROR 2002 (HY000): Can't connect to local MySQL server
- 记一次mysql启动不了的问题
- mysql出现乱码
- ubuntu系统内mysql出现乱码
- mysql数据库导入导出
- ubuntu下卸载mysql重装
- mysql获取插入时自增ID值的方法
- 执行脚本拉去远程服务器mysql数据
- 数据库_MySQL_查询时强制区分大小写的方法
- MySQL数据库知识点
- mysql升级报错innodb_table_stats" not found处理
- Mysql新增自增长主键列