Modifying the data encoding format for MySQL

Source: Internet
Author: User

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

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.