When inserting mysql database Chinese information in the cmd console, the insertion failure solution is as follows: mysql Chinese Information

Source: Internet
Author: User

When inserting mysql database Chinese information in the cmd console, the insertion failure solution is as follows: mysql Chinese Information

Fault code:

Mysql> insert into t1 (name, sex, age, address) values ('zhang san', 'male', 11, 'shahe '); ERROR 1366 (HY000 ): incorrect string value: '\ xD5 \ xC5 \ xC8 \ xFD' for column 'name' at row 1


This fault is caused by data insertion failure due to inconsistent Chinese encoding.


Generally, an error occurs when a mysql database inserts Chinese information, which is caused by inconsistent Chinese encoding. Currently, the supported Chinese encoding formats include UTF-8, gbk, and gb2312, while the database, jsp page, console, and Java code must be encoded as much as possible, otherwise, it may cause unnecessary troubles.


After searching, I found that the encoding format of my database is UTF-8, as shown below:

[mysql]default-character-set=utf8


This information is in the my. ini file under the mysql installation directory. For example, my. ini under C: \ Program Files \ MySQL Server 5.5.


The encoding format of our console is: gbk, as shown in:


In the console, choose Start> Run. In the run window, Enter cmd and click Enter.


Because the Chinese encoding formats of the console and mysql are inconsistent, Chinese data cannot be inserted successfully. The solution is to unify the encoding formats, because the encoding formats of the console cannot be set, so we only need to change the encoding format of the database. At this time, we will change the encoding format of the database to gbk.


That is, change UTF-8 in the my. ini file to gbk. The Code is as follows:

[mysql]default-character-set=gbk

Restart the mysql server and insert Chinese data. The running result is as follows:

Mysql> insert into t1 (name, sex, age, address) values ('zhang san', 'male', 11, 'shahe '); Query OK, 1 row affected( 0.05 sec)







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.