MySQL Character set summary

Source: Internet
Author: User

One: What is a character set

The character set supports multi-faceted: The server layer (server), the database layer, the Data table (table), the field (column), the connection (connect), and the result set.
1. The character set is a set of symbols and encoding rules, and the string must have a corresponding character set. 2. The check set is the rule for this set of symbols and encodings, which defines the rules for character collation and comparison between strings. 3. Non-ASCII characters in different character sets, the required number of bytes is not the same. 4. Multibyte characters are compared in characters, not in bytes. 5. Individual check sets are binary, and are compared based on the values of the corresponding characters. 6.xxx_bin stores each character in a string with binary data, which is case-sensitive. 7.xxx_general_ci is case-insensitive, CI is the abbreviation for case insensitive, which is casing insensitivity. 8.xxx_general_cs is case-sensitive,   CS is a case sensitive abbreviation, that is, casing-sensitivity.    II: Common Character Set Introduction (1): gbk/gb23121.gb2312 is a double-byte character set, both Chinese and English characters are represented by double-byte, in order to distinguish Setting its highest bit to 1.2.gb2312 is a subset of GBK, and GBK is a subset of GB18030. 3.GBK includes the large character set of CJK characters. 4. It is often sufficient to use the GBK character set. 5. International generalization is worse than utf8, but UTF8 occupies a larger database than GBK (three-byte character set). Character sets such as 6.GBK, gb2312, and UTF8 must be Unicode encoded to convert from one to the other. &NBSP;GBK, gb2312 = Unicode = Utf8utf8 = Unicode = GBK, gb2312 (2): Utf81.8-bit Unicode tuansformation Format A three-byte character set. 2. is a type of Unicode storage, variable-length character encoding, also known as the Universal Code. 3.UTF-8 uses variable-length bytes to store Unicode characters, such as ASCII letters that continue to be stored using 1 bytes, accented text, Greek text, or Cyrillic letters, and so on, using 2 bytes, while the commonly used kanji uses 3 bytes. 4. The database character set uses the UTF8 (client connection connect) and the result character set to use the UTF8 character set as much as possible, and the final HTML page is also UTF8.   http://baike.baidu.com/view/25412.htm ascii is a 7-bit character set, but cannot overwrite special characters in European languages. Lantin1 is a 7-bit character set, but cannot cover Asian, African languages.  unicode is an extension of lantin1, which addsContinent, Africa, but not all languages are supported, and ASCII is used in Unicode to indicate low efficiency. UTF8 is an extension of Unicode. In MySQL version 4.x and before, CHAR (n) indicates how many bytes can be stored, and how many characters can actually be stored are not related to the character set. After MySQL 4.x, CHAR (n) indicates how many characters can be stored and how many characters can actually be stored in relation to the character set.  char (+), UTF-8 character set, maximum length 90byte, stored 30 characters, byte number should be: 90 bytes char (five), UTF-8 character set, maximum length 90byte, stored 30 English, byte number should be: 30 bytes Char (30), the GBK character set, the maximum length of 60byte is stored in the number of characters, the bytes should be: 60 bytes char (five), the GBK character set, the maximum length of 60byte storage 30 English, the number of bytes should be: 30 bytes char (five), LATIN1 character Set, The maximum length of 30byte stored 15 characters, the number of bytes should be: 30 bytes char (), the LATIN1 character set, the maximum length of 30byte storage 30 English, bytes should be: 30 bytes    Three: How to convert character set latin1 conversion to UTF8GBK conversion to Utf8lantin1 to gbklantin1 character Set environment: Lang=en_us. iso_8859   &NBSP;CRT:DEFAULTGBK Character Set environment: Lang=en_us. Gbk/zh_cn. GBK    crt:defaultutf8 Character Set environment: Lang=en_us. UTF-8    crt:utf8 1.latin1 =>utf8 The original character set for the latin1 as an example, upgrade to UTF8 character set, the original table: old_table (Default charset= latin1), new table: New_table (Defaul Charset=utf8).   First step: Export old data mysqldump--default-character-set=latin1-hlocalhost-uroot-b my_db--tables old_table> old.sql   Step Two: Conversion encoding (Unix/linux environment) iconv-t utf8-f gb2312-c old.sql >new.sQL or remove the-f parameter, let Iconv automatically determine the original character set iconv-t Utf-8-C old.sql >new.sql here, assuming that the original data by default is GB2312 encoding.   Step Three: Import modify New.sql to add an SQL statement before the INSERT/UPDATE statement begins: SET NAMES utf8;  mysqldump-hlocalhost-uroot-b my_db < NEW.SQL&NBSP;&NBSP;2.GBK = UTF8 with the original character set for GBK as an example, upgrade to the UTF8 character set, the original table old_table (default CHARSET=GBK), new table: New_table ( Defalut Charset=utf8)   First step: Export old data mysqldump--default-character-set=gbk-hlocalhost-uroot-b my_db--tables old_ Table> old.sql  Second Step: conversion encoding (Unix/linux environment) Iconv-t Utf-8-C old.sql >new.sql or remove-f parameter, let Iconv automatically determine the original character set iconv-t Utf-8-C Old.sql >new.sql here, the original data is assumed to be gb2312 encoded by default.   Step Three: Import modify New.sql to add an SQL statement before the INSERT/UPDATE statement begins: SET NAMES utf8;  mysqldump-hlocalhost-uroot my_db < New.sql  3.latin1 = gbk  with the original character set as GBK, as an example, upgrade to the UTF8 character set, the original table old_table (default charset=latin1), new table: _table (Defalut Charset=utf8)   First step: Export old data mysqldump--default-character-set=latin1-hlocalhost-uroot-b my_db-- Tables old_table> old.sql  The second step: import (eliminating the second-step conversion coding work) modify the New.sql, in the insert/UPDATE statement before starting, add an SQL statement: SET NAMES gbk;  mysqldump-hlocalhost-uroot my_db < new.sql  


How to support full Unicode in MySQL databases
Https://mathiasbynens.be/notes/mysql-utf8mb4

10 minutes to learn to understand and solve MySQL garbled problem
http://cenalulu.github.io/mysql/mysql-mojibake/

The difference between character set GBK and UTF8 description
http://blog.csdn.net/zzxian/article/details/7330804

MySQL use UTF8MB4 experience vomiting blood summary
https://mp.weixin.qq.com/s?__biz=MzAwMDU2ODU3MA==&mid=2247484084&idx=1&sn= e3740e1087dc73ffcdc4b56bfeaaaa6d&chksm= 9ae7bf21ad9036370e8174995ff73775a0ff8c8a51b9995fc8675a994a768a136d187e2aa76d#rd


MySQL Character set summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.