Tuesday, February 13, 2007

MySQL 的自动断开连接问题

最近发现 MySQL 会自动断开 IDLE 时间超过 8 小时的数据库连接,从而导致一些基于数据库连接的应用程序,特别是 WEB 应用程序出错。

有两个办法可以解决这个问题:

第一个办法是修改 MySQL 的配置参数。这个参数的名称是 wait_timeout,其默认值为 28800(单位秒),刚好就是 8 小时。其意义为关闭一个连接之前在这个连接上等到行动的秒数,也就是说,如果一个连接闲置超过这个选项所设置的秒数,MySQL 会主动断开这个连接。

有实践表明,没有办法把这个值设置成无限大,即永久。因此如果你无法保证你的应用程序必定在设定的秒数内至少有一次操作,那么最好用第二个方法解决这个问题。

第二个办法是如下修改 JDBC 连接的 URL:
jdbc:mysql://hostaddress:3306/schemaname?autoReconnect=true

添加 autoReconnect=true 这个参数,即能解决这个问题。

另外,对于 Java 的应用程序,据说第三方的数据库连接池应用 Proxool 能够对断开的数据库连接发起自动重连,不过我没有用过,有兴趣的朋友可以尝试一下。

14 comments:

mao yun said...

5
mlb jerseys
ralph lauren outlet
tods outlet
cheap oakley sunglasses
lululemon outlet online
converse all star
jordan 4 retro
ed hardy clothing
coach outlet store
salomon running shoes
air jordan 4
pandora charms
discount oakley sunglasses
toms shoes outlet online
lebron shoes
marc jacobs outlet
coach factory outlet
abercrombie and fitch
ralph lauren outlet online
kate spade handbags
burberry outlet
coach outlet
lacoste polo shirts
kate spade
michael kors outlet online
louis vuitton
coach outlet store
coach outlet store
mont blanc pens for sale
ferragamo belts
tiffany and co jewelry
hollister uk
abercrombie and fitch
nike air force 1
snapback hats wholesale
lebron james shoes
air jordan concord
foamposite gold
ralph lauren outlet
pandora jewelry
air force one shoes
20150330maoqiuyun

Guo Guo said...

air max 90
bottega veneta outlet
nike air max uk
nike huarache
custom mlb jerseys
surpa sneakers
coach outlet
seattle seahawks jerseys
the north face uk
kansas city chiefs jerseys
nike outlet store
atlanta falcons jersey
chanel handbags
green bay packers jerseys
michael kors uk
los angeles clippers jerseys
burberry outlet
dallas cowboys jersey
nike running shoes
arizona cardinals jerseys
oakley sunglasses canada
the north face outlet
oakley sunglasses
real madrid jersey
cleveland cavaliers jersey
pittsburgh steelers jersey
north face jackets
soccer shoes
mizuno running
san francisco 49ers jerseys
dansko outlet
new orleans saints jerseys
new york jets jerseys
air jordan shoes
los angeles lakers jerseys
north face outlet
mulberry uk
hermes belt
stuart weitzman boots
washington redskins jerseys
wei20150610

oakleyses said...

oakley sunglasses, longchamp outlet, ugg boots, chanel handbags, nike air max, longchamp, christian louboutin outlet, michael kors outlet, oakley sunglasses, tiffany and co, replica watches, tory burch outlet, nike air max, ray ban sunglasses, michael kors outlet, louboutin shoes, jordan shoes, louis vuitton outlet, louis vuitton, ray ban sunglasses, longchamp outlet, polo ralph lauren outlet, replica watches, kate spade outlet, oakley sunglasses, polo ralph lauren outlet, cheap oakley sunglasses, ugg boots, nike free, tiffany jewelry, michael kors outlet, uggs on sale, louis vuitton outlet, michael kors, oakley sunglasses, louboutin, louis vuitton, michael kors outlet, ray ban sunglasses, prada handbags, louis vuitton, burberry, burberry outlet online, gucci outlet

oakleyses said...

nike blazer, michael kors, nike free run uk, nike air max, true religion jeans, true religion jeans, air jordan pas cher, nike air max, ralph lauren uk, timberland, air max, nike roshe, tn pas cher, louboutin pas cher, true religion outlet, vans pas cher, coach outlet, hermes, ralph lauren pas cher, nike free, coach purses, michael kors, oakley pas cher, mulberry, hollister pas cher, lacoste pas cher, new balance pas cher, ray ban pas cher, vanessa bruno, burberry, hollister, michael kors, kate spade handbags, coach outlet, abercrombie and fitch, lululemon, coach factory outlet, nike roshe run, north face, nike air max, ray ban uk, michael kors, true religion jeans, converse pas cher, north face, air force, hogan, sac longchamp, longchamp pas cher, sac guess

oakleyses said...

ferragamo shoes, iphone 6s plus cases, babyliss, longchamp, reebok shoes, nike trainers, asics running shoes, oakley, iphone 5s cases, celine handbags, hollister, nfl jerseys, jimmy choo shoes, birkin bag, iphone 6s cases, iphone cases, mcm handbags, bottega veneta, giuseppe zanotti, iphone 6 plus cases, abercrombie and fitch, p90x workout, beats by dre, herve leger, north face outlet, instyler, louboutin, soccer jerseys, lululemon, nike roshe, s5 cases, timberland boots, mac cosmetics, soccer shoes, valentino shoes, insanity workout, vans shoes, hollister, ralph lauren, wedding dresses, ipad cases, chi flat iron, north face outlet, iphone 6 cases, nike air max, ghd, mont blanc, baseball bats, new balance, nike huarache

oakleyses said...

ugg pas cher, vans, moncler, moncler, canada goose, louis vuitton, ugg boots uk, canada goose, toms shoes, doudoune canada goose, moncler, louis vuitton, louis vuitton, ugg australia, juicy couture outlet, moncler, supra shoes, doke gabbana outlet, gucci, karen millen, moncler outlet, hollister, moncler, hollister, canada goose, louis vuitton, ray ban, marc jacobs, pandora jewelry, michael kors outlet online, moncler, swarovski crystal, pandora jewelry, wedding dresses, thomas sabo, moncler, bottes ugg, sac louis vuitton pas cher, nike air max, barbour, barbour jackets, pandora charms, canada goose outlet, canada goose uk, michael kors outlet, converse outlet, links of london, canada goose outlet, pandora charms, canada goose

mmjiaxin said...

celine outlet
oakley sunglasses
air jordan 11
michael kors outlet
ugg outlet
longchamp handbags outlet
ralph lauren outlet
jordan shoes 2015
toms outlet store
lacoste shirts
coach outlet store
oakley sunglasses wholesale
ralph lauren outlet
beats by dre
tory burch outlet
lebron shoes
cheap nfl jersey
true religion outlet
canada goose coats
nike trainers
mm1205

方松腾 said...

michael kors handbags,michael kors outlet,michael kors,kors outlet,michael kors outlet online,michael kors outlet online sale,michael kors handbags clearance,michael kors purses,michaelkors.com,michael kors bags,michael kors shoes,michaelkors,cheap michael kors
mlb jerseys wholesale
cheap mlb jerseys
cheap nfl jerseys
nfl jerseys wholesale
nike shoes
cheap oakley sunglasses
snapback hats
soccer jerseys,cheap soccer jerseys,cheap soccer jerseys for sale,soccer jersey,usa soccer jersey,football jerseys
cheap uggs
cheap ugg boots
ugg boots
uggs outlet
wedding dresses
chicago blackhawks

dongdong said...

20161.14wengdongdong
canada goose jacket
michael kors outlet
tommy hilfiger outlet
louis vuitton handbags
christian louboutin outlet
burberry outlet online
michael kors uk
tory burch outlet
adidas shoes uk
north face jackets
louis vuitton
coach outlet
true religion jeans
canada goose outlet
ugg boots
michael kors
michael kors outlet
nike roshe runs
burberry outlet
jeremy scott shoes
nike air jordan
coach outlet
ghd straighteners
sac longchamp
coach outlet
christian louboutin
air jordan pas cher
fake oakley sunglasses
cheap jordans
true religion outlet
kate spade outlet
christian louboutin shoes
longchamp handbags
sac longchamp pliage
ugg boots
ghd
jordan 4
michael kors outlet online
coach factory outlet
coach outlet

chenlili said...

chenlili20160629
air force 1
louboutin shoes
oakley vault
michael kors handbags
retro 11
ray ban sunglasses outlet
michael kors outlet
polo ralph lauren
coach outlet store online
adidas originals
tory burch handbags
coach outlet
louis vuitton purses
michael kors handbags
ray ban sunglasses outlet
coach outlet store online
rolex watches
designer handbags
louis vuitton bags
nike sb dunks
louis vuitton outlet stores
rolex watches
louis vuitton outlet
giuseppe zanotti outlet
ray ban sunglasses
nike blazers uk
ray ban sunglasses
coach outlet
nike store
ray ban sunglasses outlet
coach outlet
ghd hair straighteners
jordan retro 4
louis vuitton purses
coach outlet store online clearances
asics outlet
polo ralph lauren
nike sb janoski
jordan 3 white cenment

Gege Dai said...

jianbin0701
michael kors outlet
mcm outlet
michael kors outlet online
hermes outlet
nike air max
reebok shoes
michael kors outlet
replica watches
rolex watches
fitflops sale clearance
coach outlet online
coach outlet online
ferragamo outlet
camisetas futbol baratas
nike uk store
mulberry bags
louis vuitton neverfull sale
oakley sunglasses
mulberry handbags sale
michael kors uk outlet
tory burch outlet
louis vuitton outlet online
michael kors outlet
cheap mlb jerseys
soccer jerseys wholesale
michael kors uk
coach handbags outlet
louboutin pas cher
adidas uk store
toms outlet
lacoste shirts
oakley sunglasses uk
tory burch outlet
chrome hearts outlet

chenmeinv0 said...

michael kors handbags
pandora jewelry
louis vuitton handbags
louboutin femme
nike air max
uggs outlet
adidas outlet
michael kors handbags
toms shoes
ralph lauren outlet online
hzx20170206

Meiqing Xu said...

coach outlet online
cardinals jerseys
yeezy boost 350
coach outlet store online
ray ban sunglasses outlet
hermes outlet online
coach factory outlet online
eahawks jerseys
michael kors purse
coach outlet store online
20170310huazhen

shengda xu said...

new england patriots jerseys
polo ralph lauren
versace shoes
true religion outlet
cheap jordans
adidas uk
coach bags
wholesale nike shoes
yeezy boost 350
dansko shoes
xushengda0609