问题:
mysql> insert tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('Y400N 14.0英寸笔记本','笔记本','联','3990',default,default); ERROR 1366 (HY000): Incorrect string value: '\xB4\xE7\xB1\xCA\xBC\xC7...' for column 'goods_name' at row 1
解决方案:
首先查看自己的数据表情况:
mysql> SHOW CREATE TABLE tdb_goods; +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------+ | Table | Create Table | +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------+ | tdb_goods | CREATE TABLE `tdb_goods` ( `goods_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `goods_name` varchar(150) NOT NULL, `goods_cate` varchar(40) NOT NULL, `brand_name` varchar(40) NOT NULL, `goods_price` decimal(15,3) unsigned NOT NULL DEFAULT '0.000', `is_show` tinyint(1) NOT NULL DEFAULT '1', `is_saleoff` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`goods_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 | +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
然后执行如下命令:
mysql> SET NAMES gbk; Query OK, 0 rows affected (0.00 sec) mysql>
再然后插入数据:
mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('Y400N 14.0英寸笔记本电脑','笔记本','联想','4899',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('G150TH 15.6英寸游戏本','游戏本','雷神','8499',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('X550CC 15.6英寸笔记本','笔记本','华硕','2799',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('X240(20ALA0EYCD) 12.5英寸超极本','超级本','联想','4999',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('U330P 13.3英寸超极本','超级本','联想','4299',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('SVP13226SCB 13.3英寸触控超极本','超级本','索尼','7999',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('iPad mini MD531CH/A 7.9英寸平板电脑','平板电脑','苹果','1998',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('iPad Air MD788CH/A 9.7英寸平板电脑 (16G WiFi版)','平板电脑','苹果','3388',DEFAU LT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES(' iPad mini ME279CH/A 配备 Retina 显示屏 7.9英寸平板电脑 (16G WiFi版)','平板电脑 ','苹果','2788',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('IdeaCentre C340 20英寸一体电脑 ','台式机','联想','3499',DEFAULT,DEFAULT); Query OK, 1 row affected (0.01 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('Vostro 3800-R1206 台式电脑','台式机','戴尔','2899',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('iMac ME086CH/A 21.5英寸一体电脑','台式机','苹果','9188',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('AT7-7414LP 台式电脑 (i5-3450四核 4G 500G 2G独显 DVD 键鼠 Linux )','台式机','宏 碁','3699',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('Z220SFF F4F06PA工作站','服务器/工作站','惠普','4288',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('PowerEdge T110 II服务器','服务器/工作站','戴尔','5388',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('Mac Pro MD878CH/A 专业级台式电脑','服务器/工作站','苹果','28888',DEFAULT,DEFAULT) ; Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES(' HMZ-T3W 头戴显示设备','笔记本配件','索尼','6999',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('商务双肩背包','笔记本配件','索尼','99',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('X3250 M4机架式服务器 2583i14','服务器/工作站','IBM','6888',DEFAULT,DEFAULT); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('玄龙精英版 笔记本散热器','笔记本配件','九州风神','',DEFAULT,DEFAULT); ERROR 1366 (HY000): Incorrect decimal value: '' for column 'goods_price' at row 1 mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES(' HMZ-T3W 头戴显示设备','笔记本配件','索尼','6999',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> mysql> INSERT tdb_goods (goods_name,goods_cate,brand_name,goods_price,is_show,is_saleoff) VALUES('商务双肩背包','笔记本配件','索尼','99',DEFAULT,DEFAULT); Query OK, 1 row affected (0.03 sec) mysql> SELECT * FROM tdb_goods; +----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+ | goods_id | goods_name | goods_cate | brand_name | goods_price | is_show | is_saleoff | +----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+ | 1 | R510VC 15.6英寸笔记本 | 笔记本 | 华硕 | 3399.000 | 1 | 0 | | 2 | Y400N 14.0英寸笔记本电脑 | 笔记本 | 联想 | 4899.000 | 1 | 0 | | 3 | G150TH 15.6英寸游戏本 | 游戏本 | 雷神 | 8499.000 | 1 | 0 | | 4 | X550CC 15.6英寸笔记本 | 笔记本 | 华硕 | 2799.000 | 1 | 0 | | 5 | X240(20ALA0EYCD) 12.5英寸超极本 | 超级本 | 联想 | 4999.000 | 1 | 0 | | 6 | U330P 13.3英寸超极本 | 超级本 | 联想 | 4299.000 | 1 | 0 | | 7 | SVP13226SCB 13.3英寸触控超极本 | 超级本 | 索尼 | 7999.000 | 1 | 0 | | 8 | iPad mini MD531CH/A 7.9英寸平板电脑 | 平板电脑 | 苹果 | 1998.000 | 1 | 0 | | 9 | iPad Air MD788CH/A 9.7英寸平板电脑 (16G WiFi版) | 平板电脑 | 苹果 | 3388.000 | 1 | 0 | | 10 | iPad mini ME279CH/A 配备 Retina 显示屏 7.9英寸平板电脑 (16G WiFi版) | 平板电脑 | 苹果 | 2788.000 | 1 | 0 | | 11 | IdeaCentre C340 20英寸一体电脑 | 台式机 | 联想 | 3499.000 | 1 | 0 | | 12 | Vostro 3800-R1206 台式电脑 | 台式机 | 戴尔 | 2899.000 | 1 | 0 | | 13 | iMac ME086CH/A 21.5英寸一体电脑 | 台式机 | 苹果 | 9188.000 | 1 | 0 | | 14 | AT7-7414LP 台式电脑 (i5-3450四核 4G 500G 2G独显 DVD 键鼠 Linux ) | 台式机 | 宏碁 | 3699.000 | 1 | 0 | | 15 | Z220SFF F4F06PA工作站 | 服务器/工作站 | 惠普 | 4288.000 | 1 | 0 | | 16 | PowerEdge T110 II服务器 | 服务器/工作站 | 戴尔 | 5388.000 | 1 | 0 | | 17 | Mac Pro MD878CH/A 专业级台式电脑 | 服务器/工作站 | 苹果 | 28888.000 | 1 | 0 | | 18 | HMZ-T3W 头戴显示设备 | 笔记本配件 | 索尼 | 6999.000 | 1 | 0 | | 19 | 商务双肩背包 | 笔记本配件 | 索尼 | 99.000 | 1 | 0 | | 20 | X3250 M4机架式服务器 2583i14 | 服务器/工作站 | IBM | 6888.000 | 1 | 0 | | 21 | HMZ-T3W 头戴显示设备 | 笔记本配件 | 索尼 | 6999.000 | 1 | 0 | | 22 | 商务双肩背包 | 笔记本配件 | 索尼 | 99.000 | 1 | 0 | +----------+------------------------------------------------------------------------+---------------+------------+-------------+---------+------------+ 22 rows in set (0.00 sec) mysql>
发现问题完美解决;
因为你此时的编码是UTF8的,要显示中文就该吧编码格式改成GBK,使用以上命令修改只会影响客户端的编码显示格式,不影响服务器的编码。