ERROR 1366 (HY000): Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
来源:互联网 发布:sql trigger update 编辑:程序博客网 时间:2024/04/24 10:42
一:问题描述
mysql> insert into t2(id,name) values(1,'你好');
ERROR 1366 (HY000): Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
二:出错原因
字符集不支持中文。
mysql> show create table t2;+-------+------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+------------------------------------------------------------------------------------------------------------------------+| t2 | CREATE TABLE `t2` ( `id` int(11) DEFAULT NULL, `name` char(30) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1 |+-------+------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)字符集为latin1,故不能插入中文数据。
三:解决办法
可以将表字符集和相应的列字符集改为utf8。
mysql> alter table t2 charset utf8;Query OK, 0 rows affected (0.05 sec)Records: 0 Duplicates: 0 Warnings: 0 mysql> show create table t2;+-------+-------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------------------------------------------------------------+| t2 | CREATE TABLE `t2` ( `id` int(11) DEFAULT NULL, `name` char(30) CHARACTER SET latin1 DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-------+-------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec) mysql> insert into t2(id,name) values(2,'你好');ERROR 1366 (HY000): Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1 还是不行。这是因为之前表字符集是latin1,列的字符集没有设置,默认也跟表一样,也是latin1,故也需要修改列的字符集:
mysql> alter table t2 modify name char(30) CHARACTER SET utf8 DEFAULT NULL;Query OK, 1 row affected (2.04 sec)Records: 1 Duplicates: 0 Warnings: 0 mysql> show create table t2;+-------+----------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+----------------------------------------------------------------------------------------------------------------------+| t2 | CREATE TABLE `t2` ( `id` int(11) DEFAULT NULL, `name` char(30) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+-------+----------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec) 现在再次插入,就不再报错了。
mysql> insert into t2(id,name) values(3,'你好');Query OK, 1 row affected (0.04 sec)
0 0
- ERROR 1366 (HY000): Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
- 错误信息:Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
- Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'xxx' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xE4\xB8\x8D\xE5\xA5\xBD' for column 'description' at r
- ERROR 1366 (HY000): Incorrect string value: '\xE4\xB8\xAD\xE5\x9B\xBD' for column 'tname' at row 1
- failed:Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'name' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xE5\xB8\x82' for column 'address' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xE5\xB8\x82' for column 'address' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xC6\xF4\xD3\xC3' for column 'name' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xE7\x9A\x84' for column 'name' at row 1
- ERROR 1366 (HY000): Incorrect string value: '\xC6\xF4\xD3\xC3' for column 'name' at row 1
- 向mysql插入数据时出现Incorrect string value: '\xEF\xBF\xBD\xE9\x8F\x83...' for column...at row 1
- Incorrect string value: '\xE4\xBC\x9A\xE5\x91\x98' for column 'recipient' at row 1
- mysql:Incorrect string value: '\xE5\x8C\x97\xE4\xBA\xAC' for column 'address' at row 1
- mysql 中插入中文出现的 Incorrect string value: '\xE5\xA5\xBD\xE5\xAE\xB6...' from column错误
- Incorrect string value: '\xE5\x9E\x9A\xE5\x9B\xBD...' for column 'YD_COMPANY
- Incorrect string value: '\xE4\xB8\x80\xE7\xBA\xA7...' for column 'name' at row 1
- ERROR 1366 (HY000): Incorrect string value:’XXX’ for column 'XXX at row 1解决
- apt-get update时卡在 waiting for headers
- java DataUtil 处理类
- ListView分拦,顶部停留,两个ListView联动显示效果
- TCHAR 数组转CString 用CString的Format功能 char数组转CString用CString的构造函数
- mongodb持久化(不错)
- ERROR 1366 (HY000): Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
- C# 引用类型作为函数参数时
- zedboard各种相关资料整理中
- Linux-0.11-Lab: 五分钟实验环境
- hdu5327_Olympiad(数组前缀和)
- 鸡尾酒排序
- Gitlab忘记密码
- 07-30 课堂笔记
- iOS学习笔记2-使用Audio Queues录音,取得实时PCM数据