mysql---字符集详解

常用的字符集包括ASCII ,GB2312 , GBK , UTF-8 ,Unicode

首先要知道


ASCII编码:

用一个字节来标识0-9的数字、大小写字母、及一些标点和不可见字符。1个字节8位,可以有256种组合。标准的ASCII编码只利用一个字节的后7位(128种组合),最高位用作奇偶校验。

范围为0000 0000 - 0111 1111 即 0-127


因为ASCII最多只有256种组合,中国汉字成千上万,所以需要更多的字节来表示一个汉字,常见中文编码的有GB2312和GBK。


GB2312编码:

是中国计算机的本地编码方式,用两个字节来表示一个汉字。为了兼容ASCII编码,这两个字节的取值范围都不在0-127,而是在128-255之间。则GB2312理论上最多有128*128=16384种组合。足够表示常用的汉字。

现有以下几个数,每个数表示一个字节,问哪些是GB2312编码,哪些是用ASCII编码?数字只是随便举的

128 200 65 189 178 23 213 186 

128 200 因为两个字节都在128-255之间,所以是用GB2312编码的汉字

65 一个字节在0-127之间,所以是用ASCII编码的,实际表示的是小写字母‘a’。

189 178 同理是用GB2312编码的汉字

213 186 也是用GB2312编码的汉字


GBK编码:

是GB2312的升级版,收容了更多的汉字。它也是用两个字节表示汉字,第一个字节的理论范围依旧是128-255之间,但第二个字节范围变为0-255。理论上最多能表示128*256种组合。同样能兼容ASCII编码。

比如

128 65 65 189 178 23 213 186 

因为128不在0-127之间,所以从128开始的2个字节表示的是一个汉字

65在0-127,所以用一个字节表示小写字母‘a’。

189 178 同理189不在0-127之间,表示的是一个汉字

213 186 同理213 不在0-127之间,表示的是一个汉字


Unicode字符集:

Unicode其实只是相当于一张表,用4个字节给去全世界的文字进行了编号。


UTF-8编码:

UTF-8和Unicode的关系,相当于压缩文件与源文件的关系,UTF-8用来压缩Unicode。UTF-8是变长编码,理论上用1到6字节来表示一个字符。


最高位是0的,用1个字节来表示一个字符

最高位有n个连续的1,则用个n个字节表示一个字符。


MySql乱码问题:

乱码问题有两种可能:1、解码与对应的编码不匹配。2、数据损坏。

第一种是可以解决的,第二种数据已损坏无法还原。

对于第一种情况,要先了解MySql的各个环节

aibang.com/show/293725186-420492730/product/15358151.html
aibang.com/show/293725186-420492730/product/15358179.html
aibang.com/show/293725186-420492730/product/15358209.html
aibang.com/show/293725186-420492730/product/15358273.html
aibang.com/show/293725186-420492730/product/15358299.html
aibang.com/show/293725186-420492730/product/15358343.html
aibang.com/show/293725186-420492730/product/15358405.html
aibang.com/show/293725186-420492730/product/15358435.html
aibang.com/show/293725186-420492730/product/15358471.html
aibang.com/show/293725186-420492730/product/15358509.html
aibang.com/show/293725186-420492730/product/15358535.html
aibang.com/show/293725186-420492730/product/15358567.html
aibang.com/show/293725186-420492730/product/15358589.html
aibang.com/show/293725186-420492730/product/15358609.html
aibang.com/show/293725186-420492730/product/15358645.html
aibang.com/show/293725186-420492730/product/15358687.html
aibang.com/show/293725186-420492730/product/15358725.html
aibang.com/show/293725186-420492730/product/15358759.html
aibang.com/show/293725186-420492730/product/15358797.html
aibang.com/show/293725186-420492730/product/15358833.html
aibang.com/show/293725186-420492730/product/15358887.html
aibang.com/show/293725186-420492730/product/15358933.html
aibang.com/show/293725186-420492730/product/15358961.html
aibang.com/show/293725186-420492730/product/15358993.html
aibang.com/show/293725186-420492730/product/15359019.html
aibang.com/show/293725186-420492730/product/15359053.html
aibang.com/show/293725186-420492730/product/15359091.html
aibang.com/show/293725186-420492730/product/15359109.html
aibang.com/show/293725186-420492730/product/15359141.html
aibang.com/show/293725186-420492730/product/15359175.html
aibang.com/show/293725186-420492730/product/15359215.html
aibang.com/show/293725186-420492730/product/15359241.html
aibang.com/show/293725186-420492730/product/15359277.html
aibang.com/show/293725186-420492730/product/15359305.html
aibang.com/show/293725186-420492730/product/15359343.html
aibang.com/show/293725186-420492730/product/15359377.html
aibang.com/show/293725186-420492730/product/15359401.html
aibang.com/show/293725186-420492730/product/15359429.html
aibang.com/show/293725186-420492730/product/15359457.html
aibang.com/show/293725186-420492730/product/15359503.html
aibang.com/show/293725186-420492730/product/15359531.html
aibang.com/show/293725186-420492730/product/15359571.html
aibang.com/show/293725186-420492730/product/15359603.html
aibang.com/show/293725186-420492730/product/15359651.html
aibang.com/show/293725186-420492730/product/15359677.html
aibang.com/show/293725186-420492730/product/15359715.html
aibang.com/show/293725186-420492730/product/15359745.html
aibang.com/show/293725186-420492730/product/15359787.html
aibang.com/show/293725186-420492730/product/15359813.html
aibang.com/show/293725186-420492730/product/15359869.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值