MySQL学习笔记04 插入中文时出现ERROR 1366 (HY000)

1 环境: MySQL Server 6.0  命令行工具

2 问题 :  插入中文字符数据出现如下错误:

ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1

3 当时环境:

mysql> insert into user(id  , username , birthday, sex, address) values('' ,  '
李四' , ' -' , 'male' , 'beijing');
ERROR (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern
ame' at row 1
mysql> select * from user;
Empty set (0.00 sec) mysql> set names gbk;
Query OK, rows affected (0.00 sec) mysql> insert into user(id , username , birthday, sex, address) values('' , '
李四' , ' -' , 'male' , 'beijing');
Query OK, row affected (0.10 sec) mysql> select * from user;
+----+----------+------------+------+---------+
| id | username | birthday | sex | address |
+----+----------+------------+------+---------+
| | 李四 | - | male | beijing |
+----+----------+------------+------+---------+
row in set (0.00 sec)

4 总结

当出现乱码,就是编码的问题,可以尝试设置数据库的编码(set nams gbk)。

上一篇:office编程必不可少


下一篇:python之路day05--字典的增删改查,嵌套