Get the App
SLTechnology News&Howtos  ›  Database  › 

How to insert and display Chinese data in MySQL database

Shulou Source: shulou.com Published: 2022-05-31 18:44:11 09月28日 Update

This article mainly explains "how to insert and display Chinese data in MySQL database". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to insert and display Chinese data in MySQL database.

First, when installing the database, set the character set encoding to utf8.

1. The current character set is encoded as:

Servercharacterset:utf8Dbcharacterset:utf8Clientcharacterset:utf8Conn.characterset:utf8

Create the database below:

(1) insert Chinese data, the operation cannot be successful.

(2) modify the character set encoding to:

Servercharacterset:utf8Dbcharacterset:utf8Clientcharacterset:gbkConn.characterset:gbk

Insert Chinese data and display normally.

What conditions should be met for MySQL database to insert and display Chinese data normally?

Second, when installing the database, set the character set coding to gbk.

1. The current character set encoding is:

Servercharacterset:gbkDbcharacterset:gbkClientcharacterset:gbkConn.characterset:gbk

Create data under, insert Chinese data, operation is normal, display is normal.

two。 The current character set is encoded as utf8:

Servercharacterset:gbkDbcharacterset:utf8Clientcharacterset:utf8Conn.characterset:utf8

3. The current character set is encoded as utf8:

Servercharacterset:gbkDbcharacterset:gbkClientcharacterset:utf8Conn.characterset:utf8

Insert Chinese data, the operation cannot be performed.

Conclusion: in order to insert Chinese into the database normally, the following conditions must be met:

1. To set the character set to support gbk or utf8 in Chinese

two。 Set the ClientCharacterset and Conn.Characterset character sets of the database to gbk

According to the above tips, I changed:

SETcharacter_set_client=gbk;SETcharacter_set_connection=gbk

Then try to insert the database into Chinese, at this time there is no error, can be inserted but the query is garbled.

Change it finally.

SETcharacter_set_results=gbk

After this, all the problems have been solved, and can be inserted and displayed normally.

At this point, I believe you have a deeper understanding of "how to insert and display Chinese data in MySQL database". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data Chinese database characters character sets coding content conditions environment learning query practicality deeper success garbled interest practicality practicality simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn OPPO Reno MySQL Shulou Technology