我正在使用 Spring Boot 应用程序,尽管我指示 Hibernate 以 UTF-8
格式创建新表,但所有新表均采用 latin1
格式。
spring.jpa.properties.hibernate.connection.characterEncoding=utf-8
spring.jpa.properties.hibernate.connection.CharSet=utf-8
spring.jpa.properties.hibernate.connection.useUnicode=true
我正在使用 Hikari。
最佳答案
我的数据库有 latin1 编码:
SELECT @@character_set_database, @@collation_database;
首先修复数据库:
foreach table: ALTER TABLE @table CONVERT TO CHARACTER SET utf8;
ALTER DATABASE javabg CHARACTER SET utf8 COLLATE utf8_unicode_ci;
确保所有连接均采用 utf8 - 编辑 my.cnf:
[mysqld]
#mist: set default encoding to utf-8
init-connect='SET NAMES utf8'
character-set-server = utf8
collation-server = utf8_general_ci
关于MySQL 表不是 UTF-8,即使我指示 Hibernate 使用 UTF-8 创建它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30061227/