---
title: "Grails使用Mysql的8小时掉链接问题修复"
author: "rox"
date: "2011-08-09T11:56:00Z"
tags: []
categories: ["编程语言"]
slug: "grails-mysql-8"
draft: false
lastmod: "2011-08-09T11:56:00Z"
id: 1143327
url: "https://rox.iteye.com/blog/1143327"
---

java的应用基本上都是采用连接池，而且至少保证有一个链接可以随时使用。

mysql默认timeout是8小时，超过这个时间，mysql方会自动断开连接。

再通过连接池访问数据，就报错了。

红色部分是毫秒数，也就是一小时

 

```
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:mysql://localhost:3306/devdb"
            pooled = true
            //loggingSql = true
            driverClassName = "com.mysql.jdbc.Driver"
            username = "root"
            password = ""
            dialect = org.hibernate.dialect.MySQL5Dialect
            properties {
                validationQuery = "select 1"
                testWhileIdle = true
                timeBetweenEvictionRunsMillis = 3600000
            }
        }
    }
```