>  Q&A  >  본문

MySQL插入中文问题!

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

这个问题如何解决啊?

迷茫迷茫2765일 전352

모든 응답(2)나는 대답할 것이다

  • 高洛峰

    高洛峰2017-04-17 13:50:34

    character_set_database 设置成utf8

    회신하다
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:50:34

    跟字符集和中文半毛钱关系也没有好吗

    提示都说了:

    Duplicated entry
    

    说明你的 UNIQUE 字段重复了!

    学会解读错误啊少年

    회신하다
    0
  • 취소회신하다