character set LOGIN

character set

Key knowledge of character sets

We only need to understand:

1. Commonly used character sets

2. What character set do we use in the database

English character set:

QQ截图20161009151258.png

##ASCII

ASCII code uses a specified combination of 7-bit or 8-bit binary numbers to represent 128 or 256 possible characters. Standard ASCII code, also called Basic ASCII code, uses 7-bit binary numbers to represent all uppercase and lowercase letters, numbers 0 to 9, punctuation marks, and special control characters used in American English.

Among them:
0~31 and 127 (33 in total) are control characters or special communication characters (the rest are displayable characters), such as control characters: LF (line feed), CR (carriage return), FF ( Page feed), DEL (delete), BS (backspace), BEL (ring), etc.; communication special characters: SOH (head of text), EOT (end of text), ACK (confirmation), etc.; ASCII values are 8, 9 , 10 and 13 are converted to backspace, tab, line feed and carriage return characters respectively. They do not have a specific graphic display, but will have different effects on text display depending on the application.
32~126 (95 in total) are characters (32 is a space), of which 48~57 are ten Arabic numerals from 0 to 9.
Numbers 65 to 90 are 26 uppercase English letters, numbers 97 to 122 are 26 lowercase English letters, and the rest are some punctuation marks, arithmetic symbols, etc.

GBK

GBK is backward compatible with GB 2312 encoding. It is a Chinese character computer encoding specification defined by the People's Republic of China. The earlier version is GB2312.

Unicode

Unicode (Unicode, Universal Code, Unicode) Unicode is a character encoding scheme developed by an international organization that can accommodate all texts and symbols in the world. To meet the requirements of cross-language and cross-platform text conversion and processing.

UTF-8

is a variable-length character encoding for Unicode, and it is also a universal code. Because UNICODE takes up twice as much space as ASCII, and the high byte 0 is of no use to ASCII. In order to solve this problem, some intermediate format character sets have appeared. They are called universal conversion formats, that is, UTF (Universal Transformation Format)

Encoding to be used in actual work

In The commonly used character sets in Chinese are divided into utf-8 and GBK.

The actual ones used are as follows:

QQ截图20161009151421.png

Observe the characteristics of (Figure 1) and you will find that the MySQL character set consists of three parts:


1.Character set2.Language
3.Type

The last bin refers to the binary character set, and the following ci refers to the size that does not distinguish between characters when storing and sorting Write.

Note:

Mysql writes utf8 when writing utf-8. Do not add the middle horizontal line.

(Picture 1)


QQ截图20161009151437.png

1. About MySQL character set

MySQL’s character set support (Character Set Support) has two aspects:

Character set (Character set) and sorting method (Collation).

MySQL's support for character sets is refined to four levels: server, database, table and connection.

MySQL's specification of character sets can be refined to what character set should be used for a database, a table, and a column.

2. Check the MySQL character set

2.1. Check the character set settings

mysql> show variables like 'character_set_%';

QQ截图20161009151450.png


2.2. View the character set sorting settings

mysql> show variables like 'collation_%';

QQ截图20161009151503.png


3. Modify the MySQL character set

3.1 Modify the server Level character set

a. Temporary modification

mysql>SET GLOBAL character_set_server=utf8;

b. Permanent modification

Open /etc/mysql/my.cnf, add character-set- after [mysqld] server=utf8

3.2 Modify the database level

a. Temporary change

mysql>SET GLOBAL character_set_database=utf8;

b. Permanent change

Just change the server level

3.3 Modify the table level

mysql>ALTER TABLE table_name DEFAULT CHARSET utf8;

The changes will take effect permanently

3.4 Modify the column level modification example

mysql>ALTER TABLE `products` CHANGE `products_model` VARCHAR( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL; 更改了后永久生效

3.5 Change the connection character set

a. Temporary change: mysql> SET GLOBAL character_set_client;

b. Permanent change: Open /etc/mysql/my.cnf and add default-character-set=utf8

after [client]


Next Section
submit Reset Code
Chapter Courseware