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