About MySQL new table cannot insert Chinese problem & workaround, such as [ERR] 1366-incorrect String value: ' \xe5\xb0\x8f\xe5\xb0\x8f ' for column ' name ' at row 1

Source: Internet
Author: User

Use MySQL to insert data containing Chinese in usercase table, error [ERR] 1366-incorrect String value: ' \xe5\xb0\x8f\xe5\xb0\x8f ' for column ' name ' at row 1

The table statement and the inserted data statement are as follows

CREATE TABLE usercase (ID int primary KEY auto_increment,name varchar), sex char (2));--Inserts a data insert into Usercase (name, Sex) VALUES ("small", ' male ');

Then MySQL will have the error message

Let's take a look at the table information Usercase, using the following command

Show Table usercase;
--Usercase is the name of the table

The information is displayed as follows:

From the Engine=innodb default charset=latin1, you can see the table is Latin1, and start solving

Workaround

Enter the following directive to modify the default encoding for the Usercase table

ALTER TABLE usercase default character set UTF8;

Then look at the results of the changes

It is found that the default encoding for the Usercase table is already utf-8, but the code for name and sex is still latin1, and inserting Chinese records will still fail. The following changes are made to the encoding format of the name and sex fields

Enter the following instruction to modify the encoding of the name field

ALTER TABLE usercase change name name varchar (TEN) Character set utf8;--name is the field name of Usercase

The results are as follows

Enter the following instruction to modify the sex field encoding

ALTER TABLE usercase change sex Sex char (2) character set UTF8;

The results are as follows

After the modification, insert a data containing Chinese in the following section

Insert success, problem temporarily resolved

About MySQL new table cannot insert Chinese problem & workaround, such as [ERR] 1366-incorrect String value: ' \xe5\xb0\x8f\xe5\xb0\x8f ' for column ' name ' at row 1

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.