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:
##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.
1.Character set2.Language
3.Type
Mysql writes utf8 when writing utf-8. Do not add the middle horizontal line.
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_%';
2.2. View the character set sorting settings
mysql> show variables like 'collation_%';
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]