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