mysql - Grails 2.3.0 和 mysql 连接超时

标签 mysql grails

我有一个使用此配置连接到 mysql 数据库的 Grails 2.2.3 应用程序:

 production {
    dataSource {
        dbCreate = "update" // one of 'create', 'create-drop','update'
        url = "jdbc:mysql://localhost/database?autoReconnect=true"

        pooled = true
        properties {
            maxActive = 50
            maxIdle = 25
            minIdle = 5
            initialSize = 5
            minEvictableIdleTimeMillis = 1800000
            timeBetweenEvictionRunsMillis = 1800000
            maxWait = 10000

        }


    }

}

升级到 Grails 2.3.0 后,它停止工作,并且在应用程序上周末不活动后,我得到这个异常:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 50,139,380 milliseconds ago.  The last packet sent successfully to the server was 50,139,380 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3352)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1971)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4997)
... 5 more
Caused by: java.net.SocketException: Write failed: Broken pipe
at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)

有什么想法吗?

最佳答案

尝试将以下“testOn”属性添加到您的连接池配置中:

  properties {
    ...
    testOnBorrow = true
    testWhileIdle = true
    testOnReturn = false
    validationQuery = "SELECT 1"
  }

以各种组合方式尝试这些标志是值得的。为了在您的环境中获得最佳性能,可能需要进行更改。

关于mysql - Grails 2.3.0 和 mysql 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19454551/

相关文章:

php - MYSQL中的2个表的查询

php - 无法写入我的 MySQL 表?

grails - Grails Controller 名称中可以有数字吗

grails - JSONRPC 与 Grails

unit-testing - 如何使用脚手架模板 Test.groovy 为 Controller 生成单元测试?

url - 防止 url 上的错误请求 "ids"的 Grails 方法

sql - 如何使用存储过程根据传递的运算符 <,= by param 执行查询?

mysql - 用户向 mysql 提交内容并进行审核 : separate table?

php - 如何在每个 MySQL 字段结果之间放置标记?

sql - 将普通 SQL 表添加到 Grails 应用程序而不是使用 ORM?