1 环境: MySQL Server 6.0 命令行工具
2 问题 : 插入中文字符数据出现如下错误:
ERROR 1366 (HY000): Incorrect string value: 'xC0xEExCBxC4' for column 'usern ame' at row 1
3 当时环境:
mysql> insert into user(id , username , birthday, sex, address) values('2' , ' 李四' , '1980 12-31' , 'male' , 'beijing'); ERROR 1366 (HY000): Incorrect string value: 'xC0xEExCBxC4' for column 'usern ame' at row 1 mysql> select * from user; Empty set (0.00 sec) mysql> set names gbk; Query OK, 0 rows affected (0.00 sec) mysql> insert into user(id , username , birthday, sex, address) values('2' , ' 李四' , '1980 12-31' , 'male' , 'beijing'); Query OK, 1 row affected (0.10 sec) mysql> select * from user; +----+----------+------------+------+---------+ | id | username | birthday | sex | address | +----+----------+------------+------+---------+ | 2 | 李四 | 1980 12-31 | male | beijing | +----+----------+------------+------+---------+ 1 row in set (0.00 sec)
4 总结
当出现乱码,就是编码的问题,可以尝试设置数据库的编码(set nams gbk)。