MySQL Chinese garbled solution in Linux

Source: Internet
Author: User
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 start
service 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

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.