3
votes

Possible duplicate: Create a MySQL connection in Playframework with slick

I am using play-slick plugin to try connecting with mysql database. But I get connection timeout error every time slick tries to communicate with the Db. My application.conf file is as follow:

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"

And whenever my application tries to communicate with the database it gets this error:

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]

I have checked that mysql is listening on port 3306. There is a service mysqld that's running. Thanks for the help.

2

2 Answers

2
votes

Change slick.dbs.default.db.username to slick.dbs.default.db.user.

Hikari connection pool logs wrong username login attempts only in DEBUG level, otherwise fails with timeout silently.

Try setting com.zaxxer.hikari to DEBUG in logback.xml to see the errors.

1
votes

This may be helpful to somebody who stumbles with a similar timeout error:

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

Following what @Kairius said, i enabled com.zaxxer.hikari logging in my logback.xml file:

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

I got the following error when play-slick evolutions tried to make a connection on my app start up (one of many):

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

And i fixed that by adding ?serverTimezone=UTC into my connection string, like so:

 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
  }
}

Im using MySQL 8.0.13 and these are my sbt dependencies:

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"