简体   繁体   English

MySQL - 整理

[英]MySQL - Collate

When I create a database I am ask to choose Default Collate, when I create a table I am ask to choose Collate.当我创建一个数据库时,我被要求选择默认整理,当我创建一个表时,我被要求选择整理。 utf8_general_ci or...latin...? utf8_general_ci 或...拉丁...? What is the basis to distinguish which one is the right one?区分哪个是对的依据是什么?

A collation determines the sort order of characters, it is a set of rules for comparing characters in a character set. 排序规则确定字符的排序顺序,它是字符集中比较字符的一组规则。 Any given character set always has at least one collation.任何给定的字符集总是至少有一个排序规则。 The end of a collation name ci , cs , and bin means case insensitive , case sensitive and binary , respectively.排序规则名称cicsbin的末尾分别表示case insensitivecase sensitivebinary A binary collation like utf8_bin is usually case sensitive, too, because it makes binary string comparisons based on the numerical values of strings.utf8_bin这样的二进制排序规则通常也区分大小写,因为它根据字符串的数值进行二进制字符串比较。

This means if you want to make case insensitive select queries, where a and A are not different, you should use a collation which ends with ci.这意味着如果你想进行不区分大小写的 select 查询,其中 a 和 A 没有区别,你应该使用以 ci 结尾的排序规则。 If you want to make a case sensitive query, where a and A are different, you should use a collation which ends with cs or bin.如果要进行区分大小写的查询,其中 a 和 A 不同,则应使用以 cs 或 bin 结尾的排序规则。

If none is selected, the standard level is applied.如果没有选择,则应用标准级别。 There are various levels of collation in MySQL, they can for example be shown by MySQL 中有各种级别的排序规则,例如可以显示为

mysql> show variables like '%collation%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM