电子邮件字段的最佳字符集是什么? [英] What is the best character set for email field?

查看:195
本文介绍了电子邮件字段的最佳字符集是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 二进制
  • utf8_bin
  • utf8_unicode_ci
  • utf8_general_ci

哪个是在MySql数据库中存储唯一电子邮件的最佳方式?

Which one is the best for storing unique emails in a MySql database?

注意:该电子邮件字段将用于用户登录.

推荐答案

电子邮件地址是一段文本.因此,请勿使用二进制,请使用文本.

An e-mail address is a piece of text. Therefore, do not use binary, use text.

Utf8 似乎是一个不错的选择.我不确定电子邮件地址支持哪些字符,但是可以预期将来会越来越多的unicode字符被允许.特别是如果您在数据库的其他位置使用utf8,则不必从一种编码切换到另一种编码,只需对所有内容都使用utf8.

Utf8 seems to be a good choice. I am not sure what characters are supported for email addresses, but one can expect that there will increasingly be more unicode characters allowed in the future. Especially if you use utf8 elsewhere in your database, you don't have to switch from one encoding to another one, just use utf8 for everything.

关于在 utf8_bin utf8_unicode_ci utf8_general_ci 之间进行选择,区别只是排序规则.这意味着在比较字符串时会有所不同.

As for choosing between utf8_bin, utf8_unicode_ci and utf8_general_ci, the difference is only the collation. This means it makes a difference when comparing the strings.

现在,您必须在允许的范围和正常的范围之间进行选择.通常,电子邮件地址不区分大小写,但可以区分大小写.

Now here you have to choose between what is allowed and what is normal. Normally, email addresses are case-insensitive, but they could be case-sensitive.

因此,如果您在电子邮件列上使用唯一索引,并且只允许大小写不同的电子邮件地址,则应使用 utf8_bin ,因为以_ci结尾的排序规则表示区分大小写" -不敏感".

So if you use a unique index on your e-mail column, and want to allow for email addresses differing only in their capitalization, you should use utf8_bin, since collations ending with _ci mean "case-insensitive".

如果您使用唯一索引,并且希望避免电子邮件仅在大小写上有所不同,请使用 utf8_unicode_ci .

If you use a unique index and want to avoid emails differing only in their capitalization, then use utf8_unicode_ci.

话虽如此,我使用 utf8_unicode_ci .我希望数据库能够将johndoe@email.com和JohnDoe@email.com识别为同一地址.它比允许使用相同字符和大写字母的地址更为有用.

That being said, I use utf8_unicode_ci. I want the db to be able to recognise johndoe@email.com and JohnDoe@email.com as the same address. It is much more useful than allowing for the possibility of addresses with same characters and different capitalization.

这篇关于电子邮件字段的最佳字符集是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆