Occurs when inserting data in MySQL
mysql> INSERT INTO user values ("1", "Li Hong", "23", "Jilin Changchun", "2");
ERROR 1366 (HY000): Incorrect string value: ' \xe6\x9d\x8e\xe7\xba\xa2 ' for column ' name ' at row 1
Because Chinese is inserted in this column, modify the encoding format of the table user
Use ALTER TABLE user default character set UTF8;
Create table user with show, query
mysql> ALTER TABLE user default character set UTF8;
Query OK, 0 rows affected (0.03 sec)
records:0 duplicates:0 warnings:0
Mysql> Show create table user;
+-------+--------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------------------------------+
| Table | Create table &NBSP ; , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB SP; |
+-------+------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------- ------------------------------------------------+
| user | CREATE TABLE ' user ' (
' id ' int (one) DEFAULT NULL,
' Name ' char (+) CHARACTER SET latin1 DEFAULT NULL,
' Age ' int (one) DEFAULT NULL,
' Address ' char (+) CHARACTER SET latin1 DEFAULT NULL,
' Wage ' tinyint (4) DEFAULT NULL
) Engine=innodb DEFAULT Charset=utf8 |
+-------+------------------------------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------- ------------------------------------------------+
1 row in Set (0.01 sec)
Found the Name column, and the address column is still latin1 encoded format
Modify the encoding format of two columns with the following two lines
ALTER TABLE user change name name char (+) Character set Utf8;alter table user change address address char (+) character s ET UTF8;
That's it.
Modifying the data encoding format for MySQL