Summary--fix MySQL Chinese garbled

Source: Internet
Author: User

First analysis of the cause of MySQL Chinese garbled:

1. Latin encoding used when building the table

2, the connection database encoding is not specified

3, the write has been garbled (this situation needs to check the source data itself)

Solution Summary: 1. Specify the encoding when creating the library:
Create Database default

2. Modify the encoding of the library:

ALTER DATABASE DEFAULT CHARACTER SET UTF8 COLLATE utf8_bin

3. Modify the encoding of the table:

ALTER TABLE DEFAULT CHARACTER SET

4. Modify the encoding of the field:

ALTER TABLE VARCHAR  $ CHARACTER SET  not NULL

is to change the field encoding of DD in the MySQL database tablename table to be UTF8

Diagnostic process:

1, SHOW CREATE TABLE testtable; To view the encoding of the current table using the Build table statement if it is a Latin Latin encoding, you can use the

ALTER DATABASE DEFAULT CHARACTER SET

Encoding of the Change table

2. Use the Show create TABLE command again to view the table encoding

If the encoding in the current column is found to be incorrect, use the

ALTER TABLE VARCHAR  $ CHARACTER SET  not NULL

To encode more Yi dd this column

3, if it is still correct, then check your code in the connection method is correct

Jdbc:mysql://localhost:3306/Test?useunicode=true& characterencoding=UTF-8

Here I am a Java connection, which specifies the encoding of the connection Utf-8

It should be all right here.

4. Modify the system default encoding

Mysql>SHOW VARIABLES like 'character%'; MySQL> SETCharacter_set_client=UTF8; MySQL> SETCharacter_set_connection=UTF8; MySQL> SETCharacter_set_database=UTF8; MySQL> SETCharacter_set_results=UTF8; MySQL> SETCharacter_set_server=UTF8; MySQL> SETCollation_connection=UTF8; MySQL> SETCollation_database=UTF8; MySQL> SETCollation_server=UTF8;

Reference article:

1, http://www.2cto.com/database/201307/227538.html

2, Http://zhidao.baidu.com/link?url=WtACC0jMIsOAk6eX6kJk8qjQhga28VgsYpNPY4Oc9sWH5fgU2OQm1An-IGiV4yZ-PE80VJ5ZB-YxrAVW3Jo8ua

Summary--fix MySQL Chinese garbled

Related Article

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.