


Detailed explanation of the difference between utf8 and utf8mb4
The difference between utf8 and utf8mb4
1. Introduction
MySQL added this utf8mb4 encoding after 5.5.3 , mb4 means most bytes 4, which is specially designed to be compatible with four-byte unicode. utf8mb4 is a superset of utf8, and no other conversion is required except changing the encoding to utf8mb4. Of course, in order to save space, it is usually enough to use utf8.
2. Content description
As mentioned above, since utf8 can store most Chinese characters, why should we use utf8mb4? It turns out that the maximum character length of utf8 encoding supported by mysql is 3 characters. section, an exception will be inserted if a 4-byte wide character is encountered. The maximum Unicode character that can be encoded by three-byte UTF-8 is 0xffff, which is the Basic Multilingual Plane (BMP) in Unicode. In other words, any Unicode characters that are not in the basic multi-text plane cannot be stored using Mysql's utf8 character set. Including Emoji expressions (Emoji is a special Unicode encoding, common on ios and android mobile phones), and many uncommon Chinese characters, as well as any new Unicode characters, etc. (disadvantages of utf8).
Usually, when computers store characters, they allocate storage space according to different types of characters and encoding methods. For example, the following encoding methods;
①In ASCII encoding, one English letter (regardless of upper and lower case) occupies one byte of space, and one Chinese character occupies two bytes of space. A binary number sequence, when stored as a digital unit in the computer, is generally an 8-bit binary number, converted to decimal. The minimum value is 0 and the maximum value is 255.
②In UTF-8 encoding, one English character occupies one byte of storage space, and one Chinese character (including traditional Chinese) occupies three bytes of storage space.
③In Unicode encoding, an English character occupies two bytes of storage space, and a Chinese character (including Traditional Chinese) occupies two bytes of storage space.
④In UTF-16 encoding, the storage of an English alphabetic character or a Chinese character requires 2 bytes of storage space (some Chinese characters in the Unicode extension area require 4 bytes to store).
⑤In UTF-32 encoding, the storage of any character in the world requires 4 bytes of storage space.
Since utf8 is compatible with most characters, why should we extend utf8mb4?
With the development of the Internet, many new types of characters have been produced, such as emoji symbols, which are the little yellow face expressions we usually send when chatting. The appearance of such characters is no longer basically the same. Among the flat Unicode characters, it was impossible to use utf8 storage in MySQL, so MySQL expanded the utf8 characters and added the utf8mb4 encoding.
So, if you want to allow users to use special symbols when designing a database, it is best to use utf8mb4 encoding to store them, so that the database has better compatibility, but this design will consume more storage space.
Recommended tutorial: "php from beginner to master"
The above is the detailed content of Detailed explanation of the difference between utf8 and utf8mb4. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
