【问题标题】:Grails 2.3.0 and mysql connection timeoutGrails 2.3.0 和 mysql 连接超时
【发布时间】:2013-10-27 14:03:38
【问题描述】:

我有一个使用此配置连接到 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)

有什么想法吗?

【问题讨论】:

  • Grails 2.3.1 已经发布,所以你可以考虑先更新到那个版本。
  • 我试过了,但我在 2.3.1 上也遇到了同样的错误......
  • 你看过这张票了吗:stackoverflow.com/questions/18078777/…它可能对你有帮助!

标签: mysql grails


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    这在过去对我们有用

            properties {
                validationQuery="select 1"
                testWhileIdle=true
                timeBetweenEvictionRunsMillis=60000
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-07
      • 2011-02-05
      • 1970-01-01
      • 2012-12-19
      • 2011-03-29
      • 2018-07-15
      • 2019-03-14
      相关资源
      最近更新 更多