如何在MySQL中创建带重音的索引

时间:2013-06-25 17:30:24

标签: mysql sql indexing phpmyadmin collation

我有一个用phpMyAdmin管理的数据库。 我有一张表来保存verb tenseverb。看起来如下:

Column | Type        | Collation         |  Attributes | Null | Default | Extra
-------+-------------+-------------------+-------------+------+---------+------
form   | varchar(50) | latin1_swedish_ci |             | No   |         |
verb   | varchar(50) | latin1_swedish_ci |             | Yes  | NULL    |

我创建并索引以便更快地访问:

Keyname     | Type  | Unique | Packed | Column | Cardinality | Collation | Null | Comment
------------+-------+--------+--------+--------+-------------+-----------+------+--------
verbs_index | BTREE | Yes    | No     | form   | 1           | A         |      |
            |       |        |        | verb   | 1           | A         | YES  |

这样做的目的是在动词及其所有动词时态(form)之间建立关联,但当我尝试插入一对(formverb时出现问题)如果没有重音的形式已经存在,则带有重音。这些是与MySql相同的单词,我得到错误:

  

键'verbs_index'重复输入'form-verb'。

我想插入:

insert into verbs values('o','verb1'); (without accent)
insert into verbs values('ó','verb1'); (with accent)

我一直在查看整理资料,我已经尝试过每latinutf8

1 个答案:

答案 0 :(得分:0)

"不区分大小写"整理将比较忽略任何变化的字符串。 案例当然。但它也会忽略变音符号。例如,oOÔò被视为相等。

要了解系统上的可用排名规则,请使用SHOW COLLATION

mysql> SHOW COLLATION;
+----------------------+----------+-----+---------+----------+---------+
| Collation            | Charset  | Id  | Default | Compiled | Sortlen |
+----------------------+----------+-----+---------+----------+---------+
[...]
| latin1_german1_ci    | latin1   |   5 |         | Yes      |       1 |
| latin1_swedish_ci    | latin1   |   8 | Yes     | Yes      |       1 |
| latin1_danish_ci     | latin1   |  15 |         | Yes      |       1 |
| latin1_german2_ci    | latin1   |  31 |         | Yes      |       2 |
| latin1_bin           | latin1   |  47 |         | Yes      |       1 |
| latin1_general_ci    | latin1   |  48 |         | Yes      |       1 |
| latin1_general_cs    | latin1   |  49 |         | Yes      |       1 |
| latin1_spanish_ci    | latin1   |  94 |         | Yes      |       1 |
| latin2_czech_cs      | latin2   |   2 |         | Yes      |       4 |
| latin2_general_ci    | latin2   |   9 | Yes     | Yes      |       1 |
| latin2_hungarian_ci  | latin2   |  21 |         | Yes      |       1 |
| latin2_croatian_ci   | latin2   |  27 |         | Yes      |       1 |
[...]

告诉您将表格排序更改为latin1_general_cs_cs,区分大小写 - 好的情况+重音等等):

mysql> ALTER TABLE verbs COLLATE latin1_general_cs;