ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'name' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xD5\xC5\xC8\xFD' for column 'name'
at row 1
数据库字符集问题,查看数据库状态:
mysql> status;
--------------
mysql Ver 14.14 Distrib 5.6.12, for Win32 (x86)
Connection id: 25
Current database: information_schema
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.6.12 MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Uptime: 8 hours 54 min 47 sec
Threads: 1 Questions: 372 Slow queries: 0 Opens: 108 Flush tables: 1 Open t
ables: 62 Queries per second avg: 0.011
--------------
我要使用的库test的字符集是latin1,该字符集不支持中文字符。
查看表引擎状态:
mysql> show create table ttt;
+-------+-----------------------------------------------------------------------
-----------------------------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
-----------------------------------------------------------------------+
| ttt | CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-----------------------------------------------------------------------
-----------------------------------------------------------------------+
修改表字符集:
mysql> alter table ttt character set utf8;
Query OK, 0 rows affected (0.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table ttt;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
----------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
----------+
| ttt | CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` varchar(20) CHARACTER SET latin1 DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
----------+
修改字段字符集:
mysql> alter table ttt modify name varchar(20) character set utf8;
Query OK, 0 rows affected (1.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table ttt;
+-------+-----------------------------------------------------------------------
---------------------------------------------------------------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
---------------------------------------------------------------------+
| ttt | CREATE TABLE `ttt` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-----------------------------------------------------------------------
---------------------------------------------------------------------+
1 row in set (0.02 sec)
OK!
转载出处 http://blog.sina.com.cn/s/blog_8f7940400101by3u.html