0

I'm struggling inserting Unicode character like Chinese character into Mysql table.
The stack is Spring Data JPA and Mysql.

The method I have tried:
1, Set spring.datasource.url to support utf-8 by modifying application.properties

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, Set IDE eclipse to use utf-8 as encode method.
enter image description here

3, Set variable of mysql through my.ini and current mysql charset variables are like following:
enter image description here

However, when I tried to select all content of the table by mysql command line tool, the content of table is just messy with a sequence of question mark. Any thing I missed?

Eugene
  • 10,627
  • 5
  • 49
  • 67
  • Where do you see the contents of the table as a messy sequence of question marks? When you read the data back from in your Spring Boot application or when you do a query in command line like in `mysql` tool? – shazin Dec 17 '18 at 03:45
  • @shazin I use `mysql` command line to display the content of table by 'select * from table_name` and saw messy content. Any suggestion about it? Let me complete my question as per your comment. – Eugene Dec 17 '18 at 03:47
  • May be you have an issue with your command line tool. Can you verify this by sending a SELECT from the Spring Boot application and seeing the returned result? – shazin Dec 17 '18 at 04:22
  • @shazin Thanks, your guess is correct. I tried to get all rows on that table and the result is as expected. – Eugene Dec 17 '18 at 06:29

1 Answers1

0

If you are using Windows, and have established UTF-8 via chcp 65001, then do SET NAMES utf8mb4; in the mysql commandline tool. This should override the cp850 in that screenshot.

If you are using terminal in a *nix system, then it may be defaulted to UTF-8. So, again, use SET NAMES utf8mb4;.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Hi James, I tried to type `chcp 65001` at the windows command line firstly, and I type mysql -u user_name -p to launch mysql command line tool. After that, I typed 'SET NAMES utf8mb4`. The content of the table did change but still messy. Any other suggestion. Thanks. – Eugene Dec 18 '18 at 07:02
  • @Gearon - do any of the cases [_here_](https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored) match "messy"? – Rick James Dec 18 '18 at 16:44