MySQL cannot insert Chinese and display Chinese

Source: Internet
Author: User

A) cannot display the Chinese solution:

Reference: http://bbs3.chinaunix.net/thread-880131-1-1.html

1:windows platform, because the Windows operating system defaults to using the gb2312 character, and when MySQL is installed,

The default is that both the client and the server use Latin1, so this results in a mismatch between the character set and the character checksum.

This time only need to find the MySQL configuration file My.ini find Default-character_set, change his parameters

Into gb2312 on it, a total of two such parameters, one is on the customer, one is the server, I generally built

The server is set up as an international character UTF8.
2:linux platform, when installing MySQL on Linux platform, gives the freedom is very big, you can install

option. Find the character settings for the database in the/configure (this will also bother you to read the Readme installation file), this time

It is best to set the character to GBK, because this character set is the Chinese character set installed by the Linux platform, and then

Locate the My.cnf file under/etc (this file will be transferred to/etc/by itself after installing MySQL, unless you are

RPM installation). It is important to note that many of the tools in Linux do not support Chinese, even if it is VI, you can STARTX

After executing the command kwrite, to compile the file, this graphic mutation software has an option to convert what you write

into any character set, very good,

II) cannot insert Chinese solution:

Reference: Http://blog.csdn.net/ancky_zhang/archive/2008/10/15/3078540.aspx

View the structure of a table:mysql> show create table users;

Mysql> Show create table users;
+-------+-----------------------------------------------------------------------
------------------------------------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
------------------------------------------------------------------------------+
| Users | CREATE TABLE ' users ' (
' userid ' int (one) default NULL,
' username ' char (character set latin1 default NULL)
) Engine=innodb DEFAULT CHARSET=GBK |
+-------+-----------------------------------------------------------------------
------------------------------------------------------------------------------+
1 row in Set (0.00 sec)

In this case, insert Chinese into the table and then there is an error.
Mysql> INSERT into users values (88, ' Chinese ');
ERROR 1366 (HY000): Incorrect string value: ' \xd6\xd0\xce\xc4 ' for column ' Usern
Ame ' at row 1
Mysql> INSERT into users values (88, ' Chinese ');
ERROR 1366 (HY000): Incorrect string value: ' \xd6\xd0\xce\xc4 ' for column ' Usern
Ame ' at row 1

  Also change the username character set of the users table.
Mysql> ALTER TABLE users modify username char (character set GBK;
ERROR 1366 (HY000): Incorrect string value: ' \xc0\xee\xcb\xc4 ' for column ' Usern
Ame ' at row 1
Mysql> ALTER TABLE users modify username char (character set GBK;
ERROR 1366 (HY000): Incorrect string value: ' \xc0\xee\xcb\xc4 ' for column ' Usern
Ame ' at row 1

Changing the username character set operation did not succeed because there is already data in the table
Emptying the data in the Users table
mysql> TRUNCATE TABLE users;
Query OK, 3 rows affected (0.01 sec)

  To change the character set of username in the user table from new
Mysql> ALTER TABLE users modify username char (character set GBK;
Query OK, 0 rows affected (0.06 sec)
records:0 duplicates:0 warnings:0

  Then insert Chinese characters, insert successfully.
Mysql> INSERT into users values (88, ' Chinese ');
Query OK, 1 row affected (0.01 sec)

Mysql> select * from users;
+--------+----------+
| UserID | Username |
+--------+----------+
| 88 | English |
+--------+----------+
1 row in Set (0.00 sec)

Here is an example of my own

MySQL cannot insert Chinese and display Chinese

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.