简体   繁体   中英

How do I set SQL mode in the JDBC connection string for MySQL 8?

I recently upgraded my MySQL instance from 5.7 to 8.0. I connected to my old instance using JDBC and a connection string that looked like this:

jdbc:mysql://[host:port]/[database]/?sessionVariables=sql_mode=''

It seems to be a bug in MySQL Connector/J. I have raised a bug report for it:

https://bugs.mysql.com/bug.php?id=92485

Try this for MySQL 8.0 in your JDBC connection string:

jdbc:mysql://[host:port]/[database]/?sessionVariables=&&sql_mode=''

eg

jdbc:mysql://localhost:3306/dbName?sessionVariables=&&sql_mode=''



For MySQL 7.0 in your JDBC connection string:

jdbc:mysql://[host:port]/[database]/?sessionVariables=sql_mode=''

eg

jdbc:mysql://localhost:3306/dbName?sessionVariables=sql_mode=''

我认为这可能是因为 sql_mode 中没有任何内容。

I faced the same problem with an old project and setting sessionVariables=sql_mode=''<\/code> didn't work in my case. It was totally ignored. Finally I found this bug report<\/a> and its explanation:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM