MySQL系统变量interactive_timeout 与 wait_timeout
来源:互联网 发布:苹果 fbi 知乎 编辑:程序博客网 时间:2024/04/29 14:01
http://blog.chinaunix.net/u/14014/showart_490462.html
mysql>show variables like '%timeout';
打印结果如下:
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| connect_timeout | 5 |
| delayed_insert_timeout | 300 |
| interactive_timeout | 28800 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+----------------------------+-------+
interactive_timeout 需在mysql_connect()设置CLIENT_INTERACTIVE选项后起作用,并被赋值为wait_timeout;
mysql>set wait_timeout = 10; 对当前交互链接有效;
mysql>set interactive_timeout = 10; 对后续起的交互链接有效;
该超时时间单位是秒,从变量从上次SQL执行后算起;当前空闲若超过该时间,则也会被强制断开。
http://blog.sina.com.cn/s/blog_473d5bba0100051j.html
在你的MySQL中配置好wait-timeout参数
我对wait-timeout这个参数的理解:MySQL客户端的数据库连接闲置最大时间值。
说得比较通俗一点,就是当你的MySQL连接闲置超过一定时间后将会被强行关闭。MySQL默认的wait-timeout值为8个小时
设置这个值是非常有意义的,比如你的网站有大量的MySQL链接请求(每个MySQL连接都是要内存资源开销的),由于你的程序的原因有大量的连接请求空闲啥事也不干,白白占用内存资源,或者导致MySQL超过最大连接数从来无法新建连接导致“Too many connections”的错误。在设置之前你可以查看一下你的MYSQL的状态(可用show processlist),如果你发现你的MYSQL中有大量的Sleep进程,哪么你真的需要设置你的wait-timeout了。如果你设置wait-timeout=10,MySQL中的所有Sleep线程最多只能“睡”10秒,之后就被强行关闭了。
这对于一些负荷比较重的MySQL还是比较有用的
C3P0是一个随Hibernate一同分发的开源的JDBC连接池, 它位于lib目录下。 如果你设置了hibernate.c3p0.*相关的属性, Hibernate将使用 C3P0ConnectionProvider来缓存JDBC连接。 如果你更原意使用Proxool, 请参考发 行包中的hibernate.properties并到Hibernate网站获取更多的信息。
这是一个使用C3P0的hibernate.properties样例文件(来自Hibernate包中etc目录下):
###########################
### C3P0 Connection Pool###
###########################
#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
#hibernate.c3p0.validate false
在hibernate.cfg.xml文件里面加入如下的配置:
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">100</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
完整示例如下(hibernate.properties):
hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
- MySQL系统变量interactive_timeout 与 wait_timeout
- MySQL系统变量interactive_timeout 与 wait_timeout
- MySQL Sleep 优化 系统变量interactive_timeout 与 wait_timeout
- Mysql wait_timeout interactive_timeout变量
- mysql interactive_timeout wait_timeout区别
- interactive_timeout与wait_timeout
- wait_timeout与interactive_timeout
- mysql wait_timeout和interactive_timeout总结
- mysql wait_timeout和interactive_timeout总结
- MySQL中的配置参数interactive_timeout和wait_timeout
- MySQL中的配置参数interactive_timeout和wait_timeout
- MySQL中的配置参数interactive_timeout和wait_timeout
- MySQL中interactive_timeout和wait_timeout的区别
- [MySQL分享]--interactive_timeout和wait_timeout小结(interactive_timeout会覆盖wait_timeout)
- 设置mysql的interactive_timeout和wait_timeout的值
- 设置mysql的interactive_timeout和wait_timeout的值
- 设置Mysql的连接超时参数wait_timeout、interactive_timeout
- wait_timeout和interactive_timeout区别
- WINDOWS 2008 各版本概览
- [双语阅读]加州同性婚姻诉讼案昨日开庭
- 2010-01-12
- 图片查看器(bmp、jpg、png、动态gif) office 2007风格
- “考研”怎么说
- MySQL系统变量interactive_timeout 与 wait_timeout
- 二月奋战,基于SILVERLIGTH的一期平台新鲜出炉
- [英语阅读]韩国政府为单身公务员寻另一半
- “实名购票”怎么说
- hdu 1030 简单解法
- 在access中表中数据导出为文本文件到MySQL的问题?
- 传智播客-ejb3(2)-SLSB与SFSB
- 更新Eclipse,下载ADT(Android开发插件)
- Harry Potter and the Order of the Phoenix