Py学习  »  DATABASE

spring data jpa+mysql不支持utf-8

Gearon • 4 年前 • 931 次点击  

在mysql表中插入像汉字这样的unicode字符我很费劲。
堆栈是spring data jpa和mysql。

我尝试过的方法:
1,通过修改application.properties将spring.datasource.url设置为支持utf-8

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=UTF-8
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8
connection.useUnicode=true
connection.characterEncoding=utf-8
hibernate.connection.useUnicode=true
hibernate.connection.characterEncoding=UTF-8
spring.datasource.sqlScriptEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.jpa.show-sql = true

2、设置ide eclipse使用utf-8作为编码方法。
enter image description here

3、mysql通过my.ini设置变量和当前mysql字符集变量如下:
enter image description here

但是,当我试图通过 mysql 命令行工具,表的内容只是乱七八糟的一个问号序列。 我错过了什么吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43421
 
931 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Rick James
Reply   •   1 楼
Rick James    5 年前

如果您使用的是windows,并且已经通过 chcp 65001 然后做 SET NAMES utf8mb4; mysql 命令行工具。这将覆盖 cp850 在那张截图里。

如果你正在使用 terminal 在*nix系统中,它可能被默认为utf-8。所以,再一次,使用 设置名称utf8mb4; .