Reference: MySQL character set summary utf8mb4 has become the default character set in MySQL 8.0, with utf8mb4_0900_ai_ci as the default collation in MySQL 8.0.1 and later. Only utf8mb4 is considered for new projects UTF-8 encoding is a variable-length encoding mechanism that can store characters using 1 to 4 bytes. Due to historical issues, the utf8 encoding in MySQL is not true UTF-8, but a truncated version with a maximum length of only 3 bytes. When encountering UTF-8 encoding that takes up 4 bytes, such as emoji characters or complex Chinese characters, storage exceptions will occur. Starting from 5.5.3, MySQL began to use utf8mb4 encoding to implement full UTF-8, where mb4 means most bytes 4, which occupies a maximum of 4 bytes. Starting from 8.0, utf8mb4 will be used as the default character encoding in a certain version. Set the server default character set to utf8mb4 When creating a database, if no character set is specified, the server's default character set is used. Setting the server's default character set to utf8mb4 can improve convenience. Edit the MySQL configuration file You only need to care about 5 system variables. If all of them are changed to utf8mb4, the modification will be successful:
After adding default-character-set=utf8 under [mysqld], the server cannot be started for unknown reasons. Later I changed it like this (MySQL 5.7): [mysqld] init_connect = 'SET collation_connection = utf8mb4_unicode_ci' init_connect = 'SET NAMES utf8mb4' character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci skip-character-set-client-handshake ... [client] default-character-set=utf8mb4 The default setting for MySQL 8.0 is utf8mb4, so there is no need to change it. If you want to change it, the configuration file is as follows: [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid character-set-server = utf8mb4 [client] default-character-set=utf8mb4 Restart and confirm You can see that the system encoding, connection encoding, server encoding, and client encoding are all set to UTF-8: mysql> show variables like "%char%"; +--------------------------------------+--------------------------------+ | 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/share/mysql-8.0/charsets/ | | validate_password.special_char_count | 1 | +--------------------------------------+--------------------------------+ 9 rows in set (0.00 sec) Character set related variables in MySQL character_set_client: The character set of the client request data When creating a database, specify the character set as utf8mb4 If the database default character set is not utf8mb4, you can specify the character set when creating the database: CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; collation In addition to storage, characters also need to be sorted or compared. It is recommended to use utf8mb4_unicode_ci, but there is no problem using utf8mb4_general_ci. The default value of MySQL 8.0 is utf8mb4_0900_ai_ci, which is a type of utf8mb4_unicode_ci. The specific meanings are as follows:
utf8mb4 has become the default character set, with utf8mb4_0900_ai_ci as the default collation in MySQL 8.0.1 and later. Previously, utf8mb4_general_ci was the default collation. Since the utf8mb4_0900_ai_ci collation is now the default collation, new tables can store characters outside the Basic Multilingual Plane by default. Emojis can now be stored by default. If you need accent sensitivity and case sensitivity, you can use utf8mb4_0900_as_cs instead. Summarize This is the end of this article about MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci. For more relevant MySQL encoding utf8 and utf8mb4 content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of various practical uses of virtual device files in Linux system
>>: Solution to the problem of repeated pop-up of Element's Message pop-up window
Table of contents 1. Demand Background 2. Optimiz...
What is a file system We know that storage engine...
Our bank's MGR will be launched at the end of...
I don't know if you have noticed when making a...
Table of contents Preface 1.1 Function 1.2 How to...
Page layout has always been my concern since I st...
You can save this logo locally as a .rar file and...
In the vertical direction, you can set the cell a...
1. First check whether the system has mysql insta...
Table of contents First step installation Step 2:...
To deploy multiple sites on a server, you need to...
Separation of static and dynamic Dynamic requests...
1. How to install? 1. [Run] -> [cmd] to open t...
An interesting discovery: There is a table with a...
Preface The project requirement is to determine w...