MySQL 排序规则:latin1_swedish_ci 与 utf8_general_ci
在 MySQL 中创建表时,我应该为排序规则设置什么:
latin1_swedish_ci
或utf8_general_ci
到底什么是排序规则?
我一直在使用 latin1_swedish_ci
,它会导致任何问题吗?
What should I set for Collation when creating tables in MySQL:
latin1_swedish_ci
orutf8_general_ci
What is Collation anyway?
I have been using latin1_swedish_ci
, would it cause any problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无论你做什么,都不要尝试在 mysql 中使用默认的 swedish_ci 排序规则和 utf8(而不是拉丁语),否则你会收到错误。排序规则必须与正确的字符集配对才能工作。由于字符集和排序规则不匹配,此 SQL 将失败:
@Blaisorblade 指出解决此问题的方法是使用与瑞典排序规则一起使用的字符集:
The SQL for the cal (calendar) module for the Yii php框架有类似于上面的错误代码。希望他们现在已经修好了。
Whatever you do, don't try to use the default swedish_ci collation with utf8 (instead of latin) in mysql, or you'll get an error. Collations must be paired with the right charset to work. This SQL will fail because of the mismatch in charset and collation:
And @Blaisorblade pointed out that the way to fix this is to use the character set that goes with the swedish collation:
The SQL for the cal (calendar) module for the Yii php framework had something similar to the above erroneous code. Hopefully they've fixed it by now.
您可以在此处阅读有关 MySQL 5.5 的字符集和排序规则的信息:
一般字符集和排序规则
MySQL 中的字符集和排序规则
排序规则支持是支持所必需的世界上所有的书面语言。例如,在我的语言(丹麦语)中,我们有一个特殊字符“æ”。听起来像瑞典语、德语、匈牙利语(以及更多)“ä”。该字符也出现在丹麦语中,其中的单词是从其中一种语言导入的。由于排序规则的支持,我们可以正确打印并进行相同的排序(ORDER BY ...)。如果没有排序规则支持,这是不可能的。
瑞典语排序规则是 MySQL 拉丁字符集的默认排序规则。它与英语配合得很好。英语非常简单 - 它适用于所有语言,因为它没有特殊字符、重音等。但是如果您经常使用另一种语言(例如西班牙语),您可以将排序规则更改为西班牙语,因此对西班牙语字符串进行排序根据西班牙语规则正确。
一个非常特殊的排序规则示例是德语排序规则之一。它的创建是为了像德国电话簿一样进行排序。德语电话簿不遵循德语的一般规则!
如果您愿意,您可以创建自己的排序规则。排序规则可以是编译的或文本格式的。
You can read about character sets and collations as of MySQL 5.5 here:
Character Sets and Collations in General
Character Sets and Collations in MySQL
The collations support is necessary to support all the many written languages of the world. For instance in my language (Danish) we have a special character 'æ'. It sounds like Swedish, German, Hungarian (and more) 'ä' . That character also appears in Danish with words imported form one of those languages. Due to collations' support we can have both printed correctly and and the same sorted (ORDER BY ...) as being identical. Without collations support that was not possible.
Swedish collations is the MySQL default for latin charsets. It works fine with English. English is so easy - it works with everything, because it has no special characters, accents etc. But if you have another language that you use often (for instance Spanish) you could change collation to a Spanish one, so sorting of Spanish Strings would be correct according to Spanish language rules.
A very special example of a collation is one of the German ones. It was created to allowed for sorting like in German phone books. German phone books don't follow general rules of german language!
You can create your own collation if you like. Collations can be compiled or text-format.
在 Wamp Server 2.5 中,您可以通过进入 PHPAdmin 来更改排序规则,选择需要更改的数据库。这将为您提供另一组选项卡。选择名为“操作”的选项卡。在该选项卡中将有一个名为“排序规则”的部分,在下拉列表中选择所需的排序规则,然后选择“开始”。
In Wamp Server 2.5 you can change the collation by going into PHPAdmin, selecting the database you need to change. This will give you another set of tabs. Select the Tab called Operations. In that tab will be section called collation, pick the one you want in the drop-down and select go.
尝试这些:
您可以从 http://php.net/manual/en/ 查看更多信息function.htmlspecialchars.php。 :D
为我工作!不再有钻石了:)
Try these:
You can see more info from http://php.net/manual/en/function.htmlspecialchars.php. :D
Worked for me! No more diamonds :)