获取 MariaDB 中可用的排序规则的 3 种方法
如果您需要查找 MariaDB 安装中可用的排序规则,请查看以下三种方法。
声明SHOW COLLATIONS
语句是返回 MariaDB 中所有可用排序规则的快速简便方法。您可以单独使用它来返回所有排序规则,或使用 aand/orclause 过滤结果。SHOW COLLATIONS[``LIKE``](https://database.guide/sql-like-operator-for-beginners/)WHERE
例:
SHOW COLLATION LIKE 'latin7%';
结果:
+————————-+———+——+———+———-+———+ | Collation | Charset | Id | Default | Compiled | Sortlen | +————————-+———+——+———+———-+———+ | latin7_estonian_cs | latin7 | 20 | | Yes | 1 | | latin7_general_ci | latin7 | 41 | Yes | Yes | 1 | | latin7_general_cs | latin7 | 42 | | Yes | 1 | | latin7_bin | latin7 | 79 | | Yes | 1 | | latin7_general_nopad_ci | latin7 | 1065 | | Yes | 1 | | latin7_nopad_bin | latin7 | 1103 | | Yes | 1 | +————————-+———+——+———+———-+———+
在本例中,我将结果缩小到仅开头的排序规则。latin7
请注意,我们可以在文本之后立即包含子句。当我们这样做时,它会指示要匹配的排序规则名称。LIKE``SHOW COLLATION
下面是另一个同时使用子句和子句的示例:WHERE``LIKE
SHOW COLLATION
WHERE Sortlen LIKE '4'
AND Collation LIKE 'utf%';
结果:
+———————+———+—–+———+———-+———+ | Collation | Charset | Id | Default | Compiled | Sortlen | +———————+———+—–+———+———-+———+ | utf8_thai_520_w2 | utf8 | 578 | | Yes | 4 | | utf8mb4_thai_520_w2 | utf8mb4 | 610 | | Yes | 4 | | utf16_thai_520_w2 | utf16 | 674 | | Yes | 4 | | utf32_thai_520_w2 | utf32 | 738 | | Yes | 4 | +———————+———+—–+———+———-+———+
信息架构表COLLATIONS
该表包含 MariaDB 中支持的排序规则的完整列表。这是返回的相同列表。information_schema.COLLATIONS``SHOW COLLATIONS
因此,我们可以查询此表以返回我们要返回的排序规则。我们还可以将列缩小到我们感兴趣的列。
例:
SELECT *
FROM information_schema.COLLATIONS
WHERE COLLATION_NAME LIKE 'utf%'
AND SORTLEN = '4';
结果:
+———————+——————–+—–+————+————-+———+ | COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN | +———————+——————–+—–+————+————-+———+ | utf8_thai_520_w2 | utf8 | 578 | | Yes | 4 | | utf8mb4_thai_520_w2 | utf8mb4 | 610 | | Yes | 4 | | utf16_thai_520_w2 | utf16 | 674 | | Yes | 4 | | utf32_thai_520_w2 | utf32 | 738 | | Yes | 4 | +———————+——————–+—–+————+————-+———+
如您所见,它返回的列与语句返回的列相同。SHOW COLLATIONS
鉴于这使用标准的SQLSELECT语句,我们可以通过多种方式自定义我们的结果。我们还可以减少返回的列,将表与其他表联接等。
下面是减少返回的列的示例:
SELECT
COLLATION_NAME,
CHARACTER_SET_NAME
FROM information_schema.COLLATIONS
WHERE COLLATION_NAME LIKE 'utf%'
AND SORTLEN = '4';
结果:
+———————+——————–+ | COLLATION_NAME | CHARACTER_SET_NAME | +———————+——————–+ | utf8_thai_520_w2 | utf8 | | utf8mb4_thai_520_w2 | utf8mb4 | | utf16_thai_520_w2 | utf16 | | utf32_thai_520_w2 | utf32 | +———————+——————–+
信息架构表COLLATION_CHARACTER_SET_APPLICABILITY
表包含表的子集。它包含相同的排序规则和字符集,但仅此而已。我的意思是它只包含更少的列。information_schema.COLLATION_CHARACTER_SET_APPLICABILITY``information_schema.COLLATIONS
例:
SELECT *
FROM information_schema.COLLATION_CHARACTER_SET_APPLICABILITY
LIMIT 10;
结果:
+———————–+——————–+ | COLLATION_NAME | CHARACTER_SET_NAME | +———————–+——————–+ | big5_chinese_ci | big5 | | big5_bin | big5 | | big5_chinese_nopad_ci | big5 | | big5_nopad_bin | big5 | | dec8_swedish_ci | dec8 | | dec8_bin | dec8 | | dec8_swedish_nopad_ci | dec8 | | dec8_nopad_bin | dec8 | | cp850_general_ci | cp850 | | cp850_bin | cp850 | +———————–+——————–+
在本例中,我使用子句将返回的行限制为仅 10 行。否则它将返回 322 行。LIMIT