gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:04:55 25 4
gpt4 key购买 nike

我有一个用 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)之间建立关联,但是当我尝试插入一对(form)时,问题就来了,verb) 如果没有重音的形式已经存在,则带有重音。这些词与 MySql 相同,我收到错误:

Duplicate entry 'form-verb' for key 'verbs_index'.

我想插入:

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

我一直在研究排序规则,并且我已经尝试过每个 latinutf8

最佳答案

“不区分大小写”的排序规则将忽略任何类型的变化来比较字符串。当然是情况。但它也会忽略变音符号。例如,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;

关于mysql - 如何在 MySQL 中创建带重音的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com