我尝试连接到本地mysql数据库,但出现“ db-连接不可用,请求在1000ms后超时”的问题。错误。我检查了文档,但所有设置似乎都可以。数据库的最大连接设置也设置为正确的数量。
版本: 播放:2.6.15,斯卡拉:2.12.2
build.sbt
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.11"
libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.1"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "3.0.1"
application.conf
slick.dbs.default.profile = "slick.jdbc.MySQLProfile$"
slick.dbs.default.db.driver = "com.mysql.cj.jdbc.Driver"
slick.dbs.default.db.url = "jdbc:mysql://localhost:3306/db_name?characterEncoding=utf-8&useSSL=false"
slick.dbs.default.db.user = "user"
slick.dbs.default.db.password = "password"
数据库调用
val db = databaseConfigProvider.get[JdbcProfile].db
try {
Await.result(db.run(dbio.transactionally), timeout)
} catch {
case e: Exception =>
throw new RuntimeException(e.getMessage)
}