scala - 如何在Slick中设置MySQL连接的socketTimeout?

标签 scala slick hikaricp

HikariCP 在 Slick 3 库中用于连接池的配置。

根据HikariCP Rapid-Recovery为了能够“从数据库重新启动或网络分区事件中恢复”,建议设置 socketTimeout as its disabled by default.

问题是如何在slick中设置socketTimeout?

最佳答案

在 application.conf 中添加 socketTimeout 作为 JDBC URL 的一部分

db {
  profile = "slick.jdbc.MySQLProfile$"
  db {
    url = "jdbc:mysql://localhost:3306/dbname?socketTimeout=30000"
    driver = com.mysql.cj.jdbc.Driver
    user = "<user>"
    password = "<password>"
  }
}

来自MySQL Connector/J 8.0 documentation

Configuration properties can be set in one of the following ways:

  • Using the set*() methods on MySQL implementations of jdbc url java.sql.DataSource (which is the preferred method when using implementations of java.sql.DataSource)
  • As a key-value pair in the java.util.Properties instance passed to DriverManager.getConnection() or Driver.connect()
  • As a JDBC URL parameter in the URL

关于scala - 如何在Slick中设置MySQL连接的socketTimeout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56029932/

相关文章:

scala - 通过持久性ID查找actor

scala - 如何为复杂的案例类创建投影类?

java - HikariPool-1 - 在连接获取期间中断

java - 使用 hikaricp 启动 Spring Boot 时遇到问题

scala - 当状态满足某些条件时如何停止状态转换?

regex - Scala 正则表达式联合

database - Scala 异步数据库调用

java - HikariCP 的 NullPointerException

scala - 如何从 scala Map 转换为 scala.collection.immutable.HashMap?

json - Play Scala JSON 正文解析器默认值字段