SpringData JPA SpringBoot 2.0.0.RELEASE MySQL5.5.28 utf8mb4 保存 emoji

包說明html

  mysql-connector-java-5.1.45.jarjava

  MySQL:5.5.28mysql

  emoji: 🎽 👖 👘 👙 💼 👜 👝 👛spring

  JSON: \uD83C\uDFBD \uD83D\uDC56 \uD83D\uDC58 \uD83D\uDC59 \uD83D\uDCBC \uD83D\uDC5C \uD83D\uDC5D \uD83D\uDC5Bsql

  數據庫:? ? ? ? ? ? ? ?數據庫

  數據庫字符集、表等字符集:utf8mb4_unicode_ci、utf8mb4tomcat

網上的一大堆,沒說到核心點上,官方文檔以下。https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html服務器

  For Connector/J 5.1.46 and earlier: In order to use the utf8mb4 character set for the connection, the server MUST be configured with character_set_server=utf8mb4; if that is not the case, when UTF-8 is used for characterEncoding in the connection string, it will map to the MySQL character set name utf8, which is an alias for utf8mb3.url

  5.1.46早期版本,若是要支持 utf8mb4,MySQL Server服務器端必須修改 my.ini 配置文件spa

  [mysqld]

  character-set-server=utf8mb4 

  5.1.47之後版本,utf-8 映射爲 utf8mb4,不想修改服務器,就升級下驅動,並設置下鏈接字符串

  spring.datasource.url=jdbc:mysql://localhost:3306/db?characterEncoding=UTF-8  

說明

  不須要設置 spring.datasource.tomcat.init-s-q-l=SET NAMES utf8mb4,也不清楚事務裏面支不支持,並很差使

  數據庫鏈接字符串,character_set_server=utf8mb4,試了沒用

相關文章
相關標籤/搜索