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/