Heim > Fragen und Antworten > Hauptteil
我在MySQL
建了一个表categories
,结构见下:
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(128) | YES | UNI | NULL | |
+-------+--------------+------+-----+---------+----------------
然而我插入中文的时候,会报错:
mysql> insert into categories(name) values('测试');
ERROR 1062 (23000): Duplicate entry '??' for key 'name'
但是插入英文不会报错:
mysql> insert into categories(name) values('test');
Query OK, 1 row affected (0.01 sec)
我的MySQL
字符集设置如下:
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
这个问题如何解决啊?
天蓬老师2017-04-17 13:50:34
跟字符集和中文半毛钱关系也没有好吗
提示都说了:
Duplicated entry
说明你的 UNIQUE 字段重复了!
学会解读错误啊少年