MySQL插入中文问题!
迷茫
迷茫 2017-04-17 13:48:34
0
2
348

我在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/ |
+--------------------------+----------------------------+

这个问题如何解决啊?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
小葫芦

character_set_database set to utf8

Peter_Zhu

It has nothing to do with the character set and Chinese half cent

The tips are all there:

Duplicated entry

It means your UNIQUE field is repeated!

Learn to interpret mistakes, young man

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!