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)