Garbled characters are generated when Chinese characters are stored in the MySQL database. garbled characters are generated when MySQL Chinese data is read from the JSP page, and garbled characters are displayed when the Chinese data of the database table is viewed in the audit environment. To solve Chinese garbled characters, the same character set is used first. I am using gbk.1. after installing MySQL, first modify the configuration file/etc/My. CNF.
(Note: different directories may be installed. You can search my. CNF file to find my. CNF directory ). Find the my. CNF file and add the following content to the file (Note: Only add, other content in the file does not need to be changed ). [Client] default-character-set = GBK [mysqld_safe] default-character-set = GBK [mysqld] default-character-set = GBK [MySQL] default-character-set = gbk2. restart the MySQL Service (
Service mysqld startservice mysqld stop
)
Log on to the terminal and enter the MySQL Command Prompt and enter the following command: mysql> show variables like '% char %'. If the items in the list are the same as the following, the configuration is successful, + ---------------------- + --------------------- | variable_name | value + ------------------------- + ------------------- | character_set_client | utf8
| Character_set_connection | utf8 | character_set_database | utf8 | bytes | utf8 | character_set_server | utf8 | bytes | utf8 | bytes |/usr/share/MySQL/sets charf8/+ bytes ---------------------- 3. this basically solves the problem of Chinese garbled characters in MySQL. It is best to restart your operating system! Such changes can take effect immediately.
(If garbled characters occur, it is best to write a filter to filter garbled characters. All problems will be solved)
4. Create a database and specify the encoding method
CreateDatabase 'mysdb' default
Character Set utf8Collate utf8_general_ci