Mysql play-slick连接超时错误

时间:2015-12-08 09:31:01

标签: mysql playframework play-slick

可能重复:Create a MySQL connection in Playframework with slick

我正在使用play-slick插件尝试连接mysql数据库。但每次光滑尝试与Db通信时,我都会收到连接超时错误。我的application.conf文件如下:

slick.dbs.default.driver= "slick.driver.MySQLDriver$"
slick.dbs.default.db.dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
slick.dbs.default.db.properties.driver = "com.mysql.jdbc.Driver"
slick.dbs.default.db.url="jdbc:mysql://127.0.0.1:3306"
slick.dbs.default.db.username="root"
slick.dbs.default.db.password="xxxx"
slick.dbs.default.db.connectionTimeout=15s
slick.dbs.default.db.numThreads = 12
slick.dbs.default.db.connectionTestQuery="select 1"

每当我的应用程序尝试与数据库通信时,都会收到此错误:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SQLTimeoutException: Timeout after 15001ms of waiting for a connection.]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:265) ~[play_2.11-2.4.3.jar:2.4.3]

我已经检查过mysql正在侦听端口3306.有一个正在运行的服务mysqld。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

这可能对遇到类似超时错误的人有所帮助:

[SQLTransientConnectionException: db - Connection is not available, request timed out after 1000ms.]

按照@Kairius的说法,我启用com.zaxxer.hikari登录到我的logback.xml文件中:

<logger name="com.zaxxer.hikari" level="DEBUG" />

当播放流畅的演变尝试在我的应用程序上启动连接时,出现以下错误(很多):

java.sql.SQLException: The server time zone value 'COT' is unrecognized or
represents more than one time zone.

我通过在连接字符串中添加?serverTimezone=UTC来解决此问题,如下所示:

 slick.dbs.default {
  profile = "slick.jdbc.MySQLProfile$"
  db {
    driver = com.mysql.cj.jdbc.Driver
    url = "jdbc:mysql://localhost:3306/eventos?serverTimezone=UTC"
    user =root
    password =root
  }
}

我正在使用MySQL 8.0.13,这是我的sbt依赖项:

libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.1"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "3.0.1"
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.13"