Mysql cannot insert Chinese Characters

Source: Internet
Author: User
MySQL database default encoding has been utf8, default-character-setutf8, but to the database table to insert Chinese, but always appear .... xB5xA5xD1xA1forcolumn... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it. 1. Number of installations

The default encoding of MySQL database is utf8, and default-character-set = utf8. However, when inserting Chinese characters into the table in the database, it always appears .... \ xB5 \ xA5 \ xD1 \ xA1 for column... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it. 1. Number of installations

The default encoding of MySQL database is utf8, and default-character-set = utf8. However, when inserting Chinese characters into the table in the database, it always appears .... \ xB5 \ xA5 \ xD1 \ xA1 for column... after checking the online errors, I found a wonderful phenomenon. Next, let's start to introduce it.

1. When installing the database, set the character set encoding to utf8.

1. Encoding in the current character set is:

  1. Server characterset: utf8
  2. Db characterset: utf8
  3. Client characterset: utf8
  4. Conn. characterset: utf8

Create a database:

(1) The operation fails because the Chinese data is inserted.

(2) modify the character set encoding:

  1. Server characterset: utf8
  2. Db characterset: utf8
  3. Client characterset: gbk
  4. Conn. characterset: gbk

Insert Chinese data. The data is displayed normally.

2. When installing the database, set the character set encoding to gbk.

1. The current character set encoding is:

  1. Server characterset: gbk
  2. Db characterset: gbk
  3. Client characterset: gbk
  4. Conn. characterset: gbk

And insert Chinese data. The operation is normal and the display is normal.

2. The current character set is encoded as utf8:

  1. Server characterset: gbk
  2. Db characterset: utf8
  3. Client characterset: utf8
  4. Conn. characterset: utf8

3. The current character set is encoded as utf8:

  1. Server characterset: gbk
  2. Db characterset: gbk
  3. Client characterset: utf8
  4. Conn. characterset: utf8

Insert Chinese data. The operation cannot be performed.

Conclusion: To insert Chinese characters to a database normally, the following conditions must be met:

1. Set the character set to gbk or utf8 that supports Chinese characters;

2. Set the character sets of the Client Characterset And Conn. Characterset to gbk;

According to the above prompt, I changed:

  1. SET character_set_client = gbk;
  2. SET character_set_connection = gbk;

Then try again to think about inserting Chinese characters into the database. There is no error in this case. It can be inserted, but the query results are garbled.

Last modified;

  1. SET character_set_results = gbk;

After that, all the problems are solved, and the insertion can be properly displayed.

View character set commands

5. View Character Set settings

Mysql> show variables like 'collation _ % ';

Mysql> show variables like 'character _ set _ % ';

Modify Character Set

Mysql> set character_set_client = utf8;
Mysql> set character_set_connection = utf8;

Mysql> set character_set_database = utf8;

Mysql> set character_set_results = utf8;

Mysql> set character_set_server = utf8;

Mysql> set character_set_system = utf8;

Mysql> set collation_connection = utf8;

Mysql> set collation_database = utf8;

Mysql> set collation_server = utf8;

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.