17. Character set

1. Character set
Characters are the general term for various characters and symbols, including national characters, punctuation marks, graphic symbols, numbers, etc.
A character set is a collection of multiple characters. There are many types of character sets. Each character set contains a different number of characters. Common character sets include ASCII, GB2312, GBK, GB18030, UniCode, etc. To accurately process the characters of various character sets, the computer needs to perform character encoding so that the computer can recognize and store various characters.

character set description
ASCII The simplest Western coding scheme, mainly used to display modern English and other Western European languages. Use 1 byte to represent 128 characters
GB2312 National standard simplified Chinese character set, compatible with ASCII. Using 2 bytes, it can represent 7445 symbols, including 6763 Chinese characters, covering almost all high-frequency Chinese characters
GBK The expansion of GB2312 adds support for traditional characters and is compatible with GB2312. Use 2 bytes to represent 21886 characters
GB18030 Solved the encoding of Chinese, Japanese, Korean, etc., compatible with GBK. Use variable byte representation, can represent 27484 characters
Unicode Unicode is an international standard coded character set that unifies the coding of 650 languages ​​in the world and is compatible with ISO-8859-1. The Unicode character set has multiple encoding methods, namely UTF-8, UTF-16 and UTF-32

2. Character sets supported by MySQL

show character set;

Insert picture description here

3. Set the database character set

#创建数据库时指定字符集
create database databaseName character utf8 collate utf8_general_ci;

#查看数据库的字符集
show create database databaseName;

#修改数据库的字符集
alter database databaseName default character set utf8;

4. Set the data table character set

#创建表时指定字符集
create table tableName
(
...
) default charset = utf8;

#查看数据库的字符集
show create table tableName;

#修改数据表的字符集
alter table tableName convert to character set utf8;

5. Set the field character set

#创建字段时指定字符集
create table tableName(
..., 
name varchar(50) not null charset utf8, 
...
);

#修改字段字符集
alter table tableName modify name char(10) character set utf8;

6.utf8mb4
MySQL added utf8mb4 encoding after 5.5.3, mb4 is the abbreviation of most bytes 4, specially used for compatible four-byte characters, such as Emoji. The utf8 in MySQL is an alias of utf8mb3, utf8mb4 is compatible with utf8, and can represent more characters than utf8. MySQL8.0 uses utf8mb4 as the default character set.

Guess you like

Origin blog.csdn.net/Jgx1214/article/details/107496229