I use spring-data-jpa
and mysql
database. My tables character set is utf-8. Also I added ?useUnicode=yes&characterEncoding=utf8
For anyone using the HikariCP connection pool who prefers not to append the parameters directly to the JDBC URL:
The spring.datasource.connectionProperties
property was removed some time ago. Since then, you need to use connection pool specific properties as shown in @SebTheGreat's answer:
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
Hikari doesn't have a connection-properties
property, but this works:
spring.datasource.hikari.data-source-properties.useUnicode=true
spring.datasource.hikari.data-source-properties.characterEncoding=UTF-8
Try
spring.datasource.url = jdbc:mysql://localhost:3306/gehive?useUnicode=yes&characterEncoding=UTF-8
It seems issue is due to missing "-".
Reference:- https://forum.hibernate.org/viewtopic.php?f=1&t=1037497&view=next
I had the same issues, and I solved it by adding this line to my application.properties
file:
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
Note: The following didn't work:
spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
It works for me if using mysql java connector version 5.1.44 (before I used connector 8.0.17 it doesn't work)
Remember to escape any special characters, as below:
spring.datasource.url=jdbc\:mysql\://localhost\:3306/${SERVER_DB_NAME}\?useUnicode=true\&characterEncoding=utf\-8\&characterSetResults=utf\-8
In my case that's solve my issue https://mathiasbynens.be/notes/mysql-utf8mb4
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci