Springboot MyBatis Write data Chinese into a question mark? Solutions

Source: Internet
Author: User
background

There is a need to write data to the database. But when written in English, there is no problem, when written in Chinese all become a question mark '. ’。 Problem Troubleshooting

The initial write mode is written in the form of reading data from the map, which is suspected to be a data error caused by this reason.
After testing, found that even the use of model to write the way there will be a problem, suspect that the database configuration in addition to the problem.

According to the MyBatis breakpoint tracking, found an unusual place.
The specific SQL is as follows:

show VARIABLES WHERE variable_name = ' language ' OR variable_name = ' Net_write_time Out ' or variable_name = ' interactive_timeout ' or variable_name = ' wait_timeout ' or variable_name = ' charact Er_set_client ' or variable_name = ' character_set_connection ' or variable_name = ' character_set ' or Variable 
    _name = ' Character_set_server ' or variable_name = ' tx_isolation ' or variable_name = ' transaction_isolation '  or variable_name = ' character_set_results ' or variable_name = ' timezone ' or variable_name = ' time_zone ' or variable_name = ' System_time_zone ' or variable_name = ' lower_case_table_names ' or variable_name = ' max_allowed_ Packet ' or variable_name = ' net_buffer_length ' or variable_name = ' sql_mode ' or variable_name = ' Query_cach E_type ' or variable_name = ' query_cache_size ' or variable_name = ' license ' or variable_name = ' Init_connect '

The results of one of the fields found are:

Character_set_server:latin1

The rest of the string-related is UTF8. Solution

!!! Root permissions are required for the following operations;

Change the configuration of the related parameters for this machine and the server. method One:

Using Set Character_set_server=utf8
The result does not take effect because the operation is only valid for the current. Method Two:

Change the default configuration file
Server side:
Vim/etc/my.cnf
Add or change Character_set_server=utf8 in a file
After service MySQL restart restart MySQL services

Mac End:

Cd/etc 
sudo touch my.cnf
sudo vim my.cnf
add
[mysqld]
Character-set-server=utf8

[client]
Default-character-set=utf8

[MySQL]
Default-character-set=utf8

Restart MySQL service results comparison

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.