如何在 Play Framework 配置文件中为 mysql db url 设置 autoReconnect 属性?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17901034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:19:20  来源:igfitidea点击:

How to set autoReconnect property for mysql db url in Play Framework configuration file?

mysqljdbcplayframework-2.0

提问by invinc4u

I am trying to set autoReconnect=true mysql connection property in application.conf file of my Play Framework 2.0 application. But it is giving me the following error :

我正在尝试在 Play Framework 2.0 应用程序的 application.conf 文件中设置 autoReconnect=true mysql 连接属性。但它给了我以下错误:

Caused by: java.sql.SQLException: The connection property 'autoReconnect' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true?useUnicode=yes' is not in this set.

This is my connection string in application.conf file:

这是我在 application.conf 文件中的连接字符串:

db.default.url="mysql://db_user:db_user@localhost/mydb?autoReconnect=true"

I am trying to set this connection parameter because I am getting this error in my application after it is idle for a long time :

我正在尝试设置此连接参数,因为我的应用程序在空闲很长时间后出现此错误:

[error] c.j.b.ConnectionHandle - Database access problem. Killing off all remaining connections in the connection pool. SQL State = 08S01
[error] application - Failed to login the user : guest
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully  
received from the server was 153,398,761 milliseconds ago.  
The last packet sent successfully to the server was 153,398,762 milliseconds ago. is longer than the server configured value of 'wait_timeout'. 
You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

I also tried setting these play db parameters to fix this connection issue as mentioned here (https://groups.google.com/forum/#!topic/play-framework/KzvbZ61j9Eo) but it didn't solve the problem.

我还尝试设置这些播放数据库参数来解决这里提到的这个连接问题(https://groups.google.com/forum/#!topic/play-framework/KzvbZ61j9Eo),但它没有解决问题。

idleConnectionTestPeriod=10
testConnectionOnCheckin=true

Any guidance towards solving this problem would be appreciated.

任何解决此问题的指导将不胜感激。

Thanks.

谢谢。

回答by Omry Yadan

obviously something is appending '?useUnicode=yes' to your URI, so you end up with

显然有些东西将 '?useUnicode=yes' 附加到您的 URI,所以您最终得到

mysql://db_user:db_user@localhost/mydb?autoReconnect=true&useUnicode=yes

parsing this would give you that the value for autoReconnect is true?useUnicode=yes

解析这个会给你 autoReconnect 的值是真的吗?useUnicode=yes

dig in a bit, maybe your connection pool or data abstraction layers are doing that.

深入研究一下,也许您的连接池或数据抽象层正在这样做。

回答by AIMIN PAN

You have 2 connection parameters, concatenate them with & instead of ? :

您有 2 个连接参数,用 & 而不是 ? :

mysql://db_user:db_user@localhost/mydb?autoReconnect=true&useUnicode=yes