utf-8和latin1 [英] utf-8 vs latin1

查看:595
本文介绍了utf-8和latin1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用utf8作为使用latin1的字符集有什么优点/缺点?

What are the advantages/disadvantages between using utf8 as a charset against using latin1?

如果utf可以支持更多的字符,更好的选择?是否有理由选择latin1?

If utf can support more chars and is used consistently wouldn't it always be the better choice? Is there any reason to choose latin1?

推荐答案

latin1 它是一个单字节编码,因此它可以存储更多的字符在相同的存储空间量,因为MySql中的字符串数据类型的长度取决于编码。手册说明

latin1 has the advantage that it is a single-byte encoding, therefore it can store more characters in the same amount of storage space because the length of string data types in MySql is dependent on the encoding. The manual states that


要计算用于存储特定CHAR,
VARCHAR或TEXT列值的字节数,必须考虑
字符用于该列的值以及值是否包含
多字节字符。特别是,当使用utf8(或utf8mb4)
Unicode字符集时,您必须记住,并非所有字符
使用相同的字节数,并且最多可以需要三(4)个字节
每个字符。有关用于不同
类别的utf8或utf8mb4字符的存储的详细信息,请参见第10.1.10节
Unicode支持。

To calculate the number of bytes used to store a particular CHAR, VARCHAR, or TEXT column value, you must take into account the character set used for that column and whether the value contains multi-byte characters. In particular, when using the utf8 (or utf8mb4) Unicode character set, you must keep in mind that not all characters use the same number of bytes and can require up to three (four) bytes per character. For a breakdown of the storage used for different categories of utf8 or utf8mb4 characters, see Section 10.1.10, "Unicode Support".

此外,大量的字符串操作(如接受子字符串和排序规则相关的比较)使用单字节编码更快。

Furthermore lots of string operations (such as taking substrings and collation-dependent compares) are faster with single-byte encodings.

,latin1不是一个严肃的竞争者,如果你关心国际化。当您要存储已知的安全值(例如百分比编码的网址)时,这是一个适当的选择。

In any case, latin1 is not a serious contender if you care about internationalization at all. It can be an appropriate choice when you will be storing known safe values (such as percent-encoded URLs).

这篇关于utf-8和latin1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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