In-depth Mysql character set settings, in-depth mysql character set
In-depth Mysql character set settings, in-depth mysql character set
There is a character set converter between the mysql client and the mysql server. character_set_client =>gbk: The converter knows that the encoding sent by the client is in gbk format character_set_connection=>gbk: Convert the data sent from the client into gbk format character_set_results =>gbk: Note: The above three character sets can be set uniformly using set names gbk example: create table test( name varchar(64) NOT NULL )charset utf8;#utf8 here represents the server-side character encoding First, insert a piece of data into the data table test inert into test values('test'); Then, the data "test" is saved in the "utf8" format in the database process: First, the data is sent to the Mysql server through the mysql client. When passing through the character set converter, since the character_set_connection value is gbk, the data sent by the client will be converted into gbk format. Then, the character set converter will When the data is to be transmitted to the server, it is found that the server saves the data in utf8, so it will automatically convert the data from gbk to utf8 format internally. When will garbled characters appear? Convert the client data into utf8 format through header('Content-type:text/html;charset=utf8'); when the data passes through the "character set converter", because character_set_client=gbk, character_set_connection is also equal to gbk , so the data transmitted from the client (actually in utf8 format) will not be converted. However, when the character set converter sends the data to the server, it finds that the format required by the server is utf8, so it will process the current data as gbk format and convert it to utf8 (however, this step Actually it's wrong. 2. When the result does not match the client page Set the format of the returned result to utf8, but the format accepted by the client is gbk, so garbled characters will appear.All available character sets can be displayed through the show character set syntax latin character set Note: The Maxlen column shows the maximum number of bytes used to store a character. utf8 character set gbk character set When will data be lost? Comparing the above three pictures, we can know that the maximum number of bytes used to store a character is different in each character set, with utf8 being the largest and latin being the smallest. Therefore, if it is not handled properly when passing through the character set converter, data will be lost and it will be irreparable. for example: When changing the value of character_set_connection to lantin The gbk data sent from the client will be converted into lantin1 format, because the data in gbk format takes up more characters, which will cause data loss. Summary:

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

As the amount of data continues to increase, database performance has become an increasingly important issue. Hot and cold data separation processing is an effective solution that can separate hot data and cold data, thereby improving system performance and efficiency. This article will introduce how to use Go language and MySQL database to separate hot and cold data. 1. What is hot and cold data separation processing? Hot and cold data separation processing is a way of classifying hot data and cold data. Hot data refers to data with high access frequency and high performance requirements. Cold data

To what extent can I develop MySQL database skills to be successfully employed? With the rapid development of the information age, database management systems have become an indispensable and important component in all walks of life. As a commonly used relational database management system, MySQL has a wide range of application fields and employment opportunities. So, to what extent do MySQL database skills need to be developed to be successfully employed? First of all, mastering the basic principles and basic knowledge of MySQL is the most basic requirement. MySQL is an open source relational database management

How to use MySQL database for time series analysis? Time series data refers to a collection of data arranged in time order, which has temporal continuity and correlation. Time series analysis is an important data analysis method that can be used to predict future trends, discover cyclical changes, detect outliers, etc. In this article, we will introduce how to use a MySQL database for time series analysis, along with code examples. Create a data table First, we need to create a data table to store time series data. Suppose we want to analyze the number

How to use MySQL database for image processing? MySQL is a powerful relational database management system. In addition to storing and managing data, it can also be used for image processing. This article will introduce how to use a MySQL database for image processing and provide some code examples. Before you begin, make sure you have installed a MySQL database and are familiar with basic SQL statements. Create a database table First, create a new database table to store the image data. The structure of the table can be as follows

As the amount of data increases, database backup becomes more and more important. For the MySQL database, we can use the Go language to achieve automated incremental backup. This article will briefly introduce how to use Go language to perform incremental backup of MySQL database data. 1. Install the Go language environment. First, we need to install the Go language environment locally. You can go to the official website to download the corresponding installation package and install it. 2. Install the corresponding library. The Go language provides many third-party libraries for accessing MySQL databases, among which the most commonly used ones are

With the large amount of data that needs to be stored and processed, MySQL has become one of the most commonly used relational databases in application development. The Go language is becoming more and more popular among developers due to its efficient concurrency processing and concise syntax. This article will lead readers to implement reliable MySQL database connection through Go language, allowing developers to query and store data more efficiently. 1. Several ways for Go language to connect to MySQL database. There are usually three ways to connect to MySQL database in Go language, which are: 1. Third-party library

In recent years, the Go language has become increasingly popular among developers and has become one of the preferred languages for developing high-performance web applications. MySQL is also a popular database that is widely used. In the process of combining these two technologies, caching is a very important part. The following will introduce how to use Go language to handle the cache of MySQL database. The concept of caching In web applications, caching is a middle layer created to speed up data access. It is mainly used to store frequently requested data to
