Garbled problem can occur in three places
1. Encoding of the program connection to be set
Jdbc:mysql://192.168.1.1:8066/testdb?useunicode=true&characterencoding=utf8
2. MySQL database encoding to be set
1) View the MySQL server-level encoding set
First go to MySQL using command:
Mysql-uroot–p
Then execute the command to view:
Show variables like ' character% ' +--------------------------+----------------------------+| Variable_name | Value |+--------------------------+----------------------------+| character_set_client | latin1 | | character_set_connection | Latin1 | | character_set_database | UTF8 | | character_set_filesystem | binary | | character_set_ Results | NULL | | character_set_server | latin1 | | character_set_system | UTF8 | | character_sets_dir |/usr/share/mysql/charsets/|+--------------------------+----------------------------+
Edit/ETC/MYSQL/MY.CF File
Add under [client]
Default-character-set=utf8
Add under [mysqld]
Character_set_server=utf8 (If you restart the MySQL error adjustment position, at the bottom of [mysqld])
This is configured on my machine:
[Mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysqlCharacter-set-server=utf8# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0
Note:Default-character-set=utf8 can also be used at [mysqld], and Character_set_server=utf8 is used if the MySQL service fails to start.
2) Look at the database-level encoding is not consistent, using the MySQL client can see
Mysql> Show variables like ' character% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| character_set_server | utf8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
3. Code for MYCAT
The default is UTF8 format, explicitly specified under the System tab under server.xml to add the following format:
<property name= "CharSet" >utf8</property>
4. If the business requires a complex character set such as UTF8MB4, configure the corresponding modifications:
The default is UTF8 format, explicitly specified under the System tab under Server.xml to add the following format:
<property name= "CharSet" >utf8mb4</property>
The mycat character set sequence is then configured according to the character set ID of the database side:
Configure Conf/index_to_charset.properties
Corresponds to Character set id= character set
Like 45=UTF8MB4.
The encoding of the above four-point configuration is consistent, garbled will not appear.
Program Write Mycat Chinese garbled solution (also includes MySQL code modification)