In a lot of places, it is noted that if you want to use JDBC with MySQL and have support for UTF-8, you need to add useUnicode=true
in the JDBC URL.
E.g.:
However, I tried this locally using MySQL 5.7.19 on Mac OS X with mysql-connector-java 5.1.41 (pulled in by Spring Boot 1.5.3). I added a file /etc/my.cnf
with:
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
This makes sure MySQL is set up for UTF-8:
mysql> SHOW VARIABLES LIKE 'character_set%';
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.19-macos10.12-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.00 sec)
Now in my application.properties
I tried with:
spring.datasource.url=jdbc:mysql://localhost:3306/testdb
and
spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true
But in both cases, it seems to be ok. So: is the advice to add useUnicode=true
still valid?