MySQL中对重音不敏感的排序

Lee*_*Lee 11 mysql unicode collation

我试图在MySQL中实现重音和不区分大小写的排序.按照手册中的说明,这应该与utf8字符集和utf8_general_ci排序规则一起使用.

当我按照手册(在本例中http://dev.mysql.com/doc/refman/5.1/en/charset-collat​​ion-implementations.html下)"排序规则对Unicode的多字节字符集"我不明白相同的结果:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 679877
Server version: 5.1.41-log MySQL Community Server (GPL) by Remi

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SET NAMES 'utf8' COLLATE 'utf8_general_ci';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT 'a' = 'A', 'a' = 'À', 'a' = 'á';
+-----------+-----------+-----------+
| 'a' = 'A' | 'a' = 'À' | 'a' = 'á' |
+-----------+-----------+-----------+
|         1 |         0 |         0 |
+-----------+-----------+-----------+
1 row in set (0.00 sec)

mysql> 
Run Code Online (Sandbox Code Playgroud)

在手册中的示例中,这些都是1.

当我尝试直接在查询中设置排序规则时,它也无法平等对待重音字符.在这个例子中,表使用latin1,我正在转换为utf8.

mysql> select * from test;
+----------+
| k        |
+----------+
| Cárdenas |
| Cardozo  |
| Corbin   |
| Cabrero  |
+----------+

mysql> select k from test order by convert(k using utf8) collate utf8_general_ci
;
+----------+
| k        |
+----------+
| Cabrero  |
| Cardozo  |
| Corbin   |
| Cárdenas |
+----------+
4 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

它应该忽略最后一个条目中'a'的重音并将其排序.我有什么想法我做错了吗?

Ais*_*war 0

我可能在这里遗漏了一些东西......但是你不能创建一个函数(例如removeAccents)来接受一个字符串并返回非重音等效字符串,然后按 排序removeAccents(field)。我相信您也可以为此创建一个索引,这应该有助于提高性能。