Mac os mysql database to solve the Chinese garbled

Mac os mysql database to solve the Chinese garbled

Problem Description:

When using jdbc, mybatis and other frameworks, after inserting data into the database, using tools such as viewing Navicat discovered that the Chinese become garbled.

1. The questions are as follows
        sqlSessionFactory = SqlSessionFactoryUtil.getSqlSessionFactoryInstance();
        userInfo = new UserInfo();
        userInfo.setUid(UUID.randomUUID().toString());
        userInfo.setUsername("dada's mt");
        userInfo.setPassword("12345678");
        userInfo.setSex(0);
        userInfo.setNickname("哒哒");
        userInfo.setEmail("[email protected]");
        userInfo.setBirthday(new Date());
        userInfo.setType(0);

userInfo.setNickname ( "da da"); Chinese character set here, but it is software to view data? ?
Here Insert Picture Description

2. Cause:

Use the following statement to query the database coding
show variables like '% char%' ;
you can see the following results:
character_set_server is latin1 instead of utf8
Here Insert Picture Description

3. Resolution:

  • 1) plus the database connection url characterEncoding = UTF-8, such as: url: jdbc: mysql: //127.0.0.1: 3306 / spring_boot useUnicode = true & amp & characterEncoding = UTF-8?
  • 2) modify the configuration file, find a mysql configuration file (usually in / usr / local / mysql / support -files / directories may not have the new version of mysql), named my.cnf, put up / down etc, in the files tab [mysqld] at plus character-set-server = utf8 as follows:
    Note: my.cnf do not assign 777, my.cnf is wirtale words will be ignored by mysql (755 are possible)
[client]
default-character-set=utf8
port        = 3306
socket      = /tmp/mysql.sock
[mysqld]
default-storage-engine=INNODB
#设置mysql server编码为utf8
character-set-server=utf8
collation-server=utf8_general_ci
port        = 3306
socket      = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
server-id   = 1
pid-file = /usr/local/mysql/data/mysql.pid
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout

Restart mysql service, execute show variables like '% char%', as follows:
Here Insert Picture Description

Published 17 original articles · won praise 9 · views 6527

Guess you like

Origin blog.csdn.net/liuyanglglg/article/details/84782180
Recommended