How to set useUnicode=true and characterEncoding=utf8 properties on Spring-managed MySQL JDBC connection

后端 未结 5 741
醉话见心
醉话见心 2021-02-05 06:27

I\'m currently building a Spring MVC webapp and the database is the vital backend part. For whatever reason, however, Spring is refusing to process the data as UTF-8. Since the

5条回答
  •  感动是毒
    2021-02-05 06:44

    I wasted time to generate utf-8 tables. Non of above worked for me. At last I have change my mysql config file & it works like a charm. If you are in linux(I am in ubuntu, I am sure there is a file for windows) open the file /etc/mysql/my.cnf and add the following code.

    [client]
    default-character-set=utf8
    
    [mysql]
    default-character-set=utf8
    
    
    [mysqld]
    collation-server = utf8_unicode_ci
    init-connect='SET NAMES utf8'
    character-set-server = utf8
    

    Don't forget to restart mysql service.

提交回复
热议问题