何时使用utf-8和什么时候在MySQL中使用latin1? [英] When to use utf-8 and when to use latin1 in MySQL?

查看:407
本文介绍了何时使用utf-8和什么时候在MySQL中使用latin1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道MySQL 的编码具有默认的编码,而显然,需要1个字节来存储一个字符在拉丁字节1和3个字节之间来存储

I know that MySQL has default of latin1 encoding and apparently it takes 1 byte to store a character in latin1 and 3 bytes to store a character in utf-8 - is that correct?

我正在一个希望在全球范围内使用的网站上工作。我绝对需要使用 utf-8 吗?或者我可以使用latin1来取消使用?

I am working on a site that I hope will be used globally. Do I absolutely need to have utf-8? Or will I be able to get away with using latin1?

此外,我尝试将一些表从 latin1 更改为 utf8 但是我收到这个错误:
Speficief key太长了;最大密钥长度为1000字节
有没有人知道这个解决方案?我应该真的解决这个问题,或者说可以拉丁1吗?

Also, I tried to change some tables from latin1 to utf8 but I got this error: Speficief key was too long; max key length is 1000 bytes Does anyone know the solution to this? And should I really solve that or may latin1 be enough?

感谢
Alex

Thanks, Alex

推荐答案


需要1个字节来存储一个字符在latin1和3个字节中存储一个字符在utf-8 - 是否正确?

it takes 1 byte to store a character in latin1 and 3 bytes to store a character in utf-8 - is that correct?

需要 1 个字节来存储一个 latin1 1 3 个字节以存储 UTF8 字符。

It takes 1 bytes to store a latin1 character and 1 to 3 bytes to store a UTF8 character.

如果您只在字符串中使用基本的拉丁字符和标点符号( 0 128 Unicode )中,两个字符集将占用相同的长度。

If you only use basic latin characters and punctuation in your strings (0 to 128 in Unicode), both charsets will occupy the same length.


另外,我尝试将一些表从latin1更改为utf8,但是我收到此错误:Speficief键太长;最大密钥长度为1000字节有谁知道解决方案吗?如果你有一列 VARCHAR(334),那么我应该真的解决这个问题,或者说可能latin1是不够的?

Also, I tried to change some tables from latin1 to utf8 but I got this error: "Speficief key was too long; max key length is 1000 bytes" Does anyone know the solution to this? And should I really solve that or may latin1 be enough?

或更长时间, MyISAM 不要让它创建一个索引,因为列的可能性远远超过 1000 bytes。

If you have a column of VARCHAR(334) or longer, MyISAM wont't let you create an index on it since there is remote possibility of the column to occupy more that 1000 bytes.

请注意,这样长度的键很少有用。您可以创建一个前缀索引,它将几乎与任何真实世界的数据一样有选择性。

Note that keys of such length are rarely useful. You can create a prefixed index which will be almost as selective for any real-world data.

这篇关于何时使用utf-8和什么时候在MySQL中使用latin1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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