MySQL database inserted in Chinese incorrect string value: ' \xe6\x97\xb7\xe5\x85\xa8 ' for column ' Sz_name ' at row 1

Source: Internet
Author: User

There was this problem at the time of development today.

Incorrect string value: ' \xe6\x97\xb7\xe5\x85\xa8 ' for column ' Sz_name ' at row 1

Scene, inserting the Chinese parameter into the table in the MySQL database, throws this exception

When I executed the code with SQLYOG, I found that there was only a warning and there was no error, but the exception was thrown in the code, stating that the management tool SQLyog was not so strict with some of the conventions and the code would have an error. Remind yourself that you cannot ignore the warnings that appear in the Administrative Tools when you write SQL later.

Solution:

Add the DEFAULT Charset=utf8 collate=utf8_unicode_ci when you build a table with SQL statements

Here is my build statement:

CREATE TABLE ' stat_day_exception_201807 ' (
' ng_id ' bigint (a) not NULL auto_increment,
' ng_report_id ' bigint () DEFAULT NULL,
' Nt_type ' int (one) is not NULL,
' Sz_name ' varchar (255) COLLATE Utf8_unicode_ci not NULL,
' Sz_reason ' text COLLATE utf8_unicode_ci,
' Bt_charge ' int (one) DEFAULT ' 0 ',
' Ts_begin ' datetime DEFAULT NULL,
' Ts_end ' datetime DEFAULT NULL,
' Bt_attendance ' int (one) DEFAULT ' 0 ',
' Nt_count ' decimal (10,4) not NULL DEFAULT ' 0.0000 ',
' Nt_minutes ' int (one) DEFAULT ' 0 ',
' Sz_code ' varchar (255) COLLATE utf8_unicode_ci DEFAULT NULL,
' ng_user_id ' bigint () DEFAULT NULL,
' Dt_date ' datetime DEFAULT NULL,
PRIMARY KEY (' ng_id '),
KEY ' I_stat_day_exception_sys_user ' (' ng_user_id '),
KEY ' I_stat_day_exception_day ' (' dt_date ')
) Engine=innodb auto_increment=1701 DEFAULT Charset=utf8 collate=utf8_unicode_ci

MySQL database inserted in Chinese incorrect string value: ' \xe6\x97\xb7\xe5\x85\xa8 ' for column ' Sz_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.