如何在 MySQL 8 的 JDBC 连接字符串中设置 SQL 模式?
How do I set SQL mode in the JDBC connection string for MySQL 8?
我最近将我的 MySQL 实例从 5.7 升级到 8.0。
我使用 JDBC 和如下所示的连接字符串连接到我的旧实例:
jdbc:mysql://[host:port]/[database]/?sessionVariables=sql_mode=''
升级到 8.0 后导致此错误
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '='')'.
如何在 MySQL 8 的 JDBC 连接字符串中设置 SQL 模式?
我想这可能是因为 sql_mode.
中没有任何内容
这似乎是 MySQL Connector/J 中的错误。我已经为它提出了一个错误报告:
w=14=sh
w=10=sh
w=19=will.y.w=16=w
w=11=sh
w=19=shsh=22=shsh=22=shsh=16=sh
w=15=sh
w=12=]
例如
jdbc:mysql://localhost:3306/dbName?sessionVariables=sql_mode=''
我在一个旧项目中遇到了同样的问题,设置 sessionVariables=sql_mode=''
对我来说不起作用。它完全被忽略了。
最后我找到了这个 bug report 及其解释:
The driver needs the STRICT_TRANS_TABLES mode enabled to enforce JDBC compliance on truncation checks.
If you can't use STRICT_TRANS_TABLES as part of your sql_mode, then you'll have to disable truncation checks by adding "jdbcCompliantTruncation=false" as a URL configuration parameter.
确实,设置 jdbcCompliantTruncation=false
对我有用。
我最近将我的 MySQL 实例从 5.7 升级到 8.0。 我使用 JDBC 和如下所示的连接字符串连接到我的旧实例:
jdbc:mysql://[host:port]/[database]/?sessionVariables=sql_mode=''
升级到 8.0 后导致此错误
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '='')'.
如何在 MySQL 8 的 JDBC 连接字符串中设置 SQL 模式?
我想这可能是因为 sql_mode.
中没有任何内容这似乎是 MySQL Connector/J 中的错误。我已经为它提出了一个错误报告:
例如
jdbc:mysql://localhost:3306/dbName?sessionVariables=sql_mode=''
我在一个旧项目中遇到了同样的问题,设置 sessionVariables=sql_mode=''
对我来说不起作用。它完全被忽略了。
最后我找到了这个 bug report 及其解释:
The driver needs the STRICT_TRANS_TABLES mode enabled to enforce JDBC compliance on truncation checks.
If you can't use STRICT_TRANS_TABLES as part of your sql_mode, then you'll have to disable truncation checks by adding "jdbcCompliantTruncation=false" as a URL configuration parameter.
确实,设置 jdbcCompliantTruncation=false
对我有用。