[Database] MYSQL Use - Character Set

A character set

  1. Character set at what time can play a role?
    Time to save the data needs to use the character set
    data transmission, you also need to use the character set
    the character set when subsisting
    on the MySQL server, in the database, in the use of the table, in field is set
    on.
    when the server is installed, you can specify the default character set
  2. Common character sets
    ASCII: Based on a Roman alphabet character set, which uses low 7 1 byte indicates that the word
    character, the high is always 0.
    LATIN1: relative to the ASCII character set to do the expansion, still use one byte character,
    but enable high, it extends the range represents the character set.
    GB2312: Simplified Chinese characters, a character take up to two bytes
    GB: just all the Chinese characters, a character take up to two bytes
    UTF8: international universal coding, a character take up to three bytes
    UTF8MB4: international universal coding, strengthen the identification of new text on the basis of utf8 on a
    take up to four bytes of characters
/* gbk字符集最大字符串长度: 65535/2 -1 */
create table test(
    text varchar(32766)
) charset=gbk;
/* utf8字符集最大字符串长度: 65535/3 -1 */
create table test1(
    text varchar(21844)
) charset=utf8;
/* utf8mb4字符集最大字符串长度: 65535/4 -1 */
create table test4(
    text varchar(16382)
) charset=utf8mb4;
  1. View the current system mysql character set support
mysql> show variables like 'character_%';
/* 输出:
+--------------------------+------------+
| Variable_name           | Value     |
+--------------------------+------------+
| character_set_client     | utf8mb4   | 客户端来源数据使
用的字符集
| character_set_connection | utf8mb4   | 连接层字符集
| character_set_database   | utf8mb4   | 当前选中的数据库
的默认字符集
| character_set_filesystem | binary     | 文件系统字符集
| character_set_results   | utf8mb4   | 查询结果使用的字
符集
| character_set_server     | utf8mb4   | 默认的内部操作字
符集
| character_set_system     | utf8       | 系统元数据(字段
名、表名等)的字符集
| character_sets_dir       | /usr/lo... |
+--------------------------+------------+
*/
  1. Modify the character set encoding of the current system mysql
  • All changes
set names gbk;
  • Specified modification
set character_set_client = gbk;
set character_set_results = gbk;
Published 116 original articles · won praise 10 · views 1360

Guess you like

Origin blog.csdn.net/weixin_44727383/article/details/104979075