In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the example analysis of charset=utf8 in mysql, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
1. Let's take a look at a table-building statement.
Create table student (sid int primary key aotu_increment, sname varchar (20) not null, age int) charset=utf8
Think about one question:
When we create a table, when we do not specify charset=utf8 and insert Chinese at this time, why do we report an error?
When you specify charset=utf8, insert Chinese again, why can you insert Chinese again without garbled code?
2. View the character set of CMD black window
Open CMD Black window-> Mouse on top of window-> Click the right mouse button-> Properties-> Click options
From the image above, you can see that the character encoding used for input text in CMD is GBK. At the same time, when you save a file, you will often see the ANSI character set, which represents the local character set. In China, the local character set uses GBK encoding.
Have you paid attention to this problem?
The characters entered by client on the client side are all encoded by GBK. The characters stored by the mysql server are encoded by UTF8. Then, we add, delete, change and check the database and tables, and finally return to the client interface. If we want to ensure that the characters are not garbled, we must have gone through the "coding conversion process". What I want to ask is, what on earth completed this coding conversion process?
4. Several mysql operation commands that you are not familiar with
-- check all the character sets supported by the database (this command goes down by yourself). Mysql > show character set;-- to view the current status of the system, where you can see some character set settings. Mysql > status;-- view the system character set settings, including all character set settings mysql > show variables like'% char%'
The operation results are as follows:
From the picture above, we can see that there is something called "connection", which is called "connector" in Chinese. "connector" is used to carry out the "coding conversion process".
1) characteristics of connectors
① "the role of connectors":
Connect the client and the server to convert the character set. The connector has this automatic conversion function.
② "Connector Workflow":
Ⅰ first, the character of the client is sent to the connector, and the connector selects an encoding to convert it (the converted code is consistent with the coding format of the connector) for temporary storage.
The Ⅱ then converts the connector to the same encoding as the server, which is eventually stored in the server.
Ⅲ then, the result returned by the server goes through the connector again, and the connector still selects a code to convert it (the converted code is consistent with the connector's encoding format) for temporary storage.
Ⅳ finally, the connector converts the result into a character set consistent with the client, which can be displayed normally on the client.
2) the figure illustrates the function of the connector connection
Figure 1:
Figure 1 is illustrated as follows:
Figure 2:
Figure 2 illustrates as follows:
5. Actual combat demonstration of the above two pictures
1) first of all, learn about the following code.
-- 1) sets the character set of the client. Set character_set_client=gbk;-- 2) sets the character set of the connector. Set character_set_connection=utf8;-- 3) sets the character set that returns the result. Set character_set_results=gbk
2) the code demonstration process, written in detail in the sql file in the link below, can be downloaded and viewed by yourself.
Http://note.youdao.com/noteshare?id=3fe60a490637d1a51ac78bf4a9e7e4d0&sub=511D73BDDEA34D9BAC565249035D74A8
6. Two reasons for garbled codes
Decoding and actual coding, inconsistent caused by garbled, can be repaired.
In the process of transmission, due to inconsistent coding, resulting in the loss of some bytes, resulting in garbled, irreparable.
1) garbled code caused by inconsistency between encoding and decoding
2) the garbled code caused by the loss of bytes during transmission.
7. Analysis of the actual situation (if nothing is set, what is the default of the system?)
1) take a closer look at the following pictures
According to the above picture, you can know (understand the following text description):
Figure 2:
2) the meaning of set names gbk
When the client, connector, and return values have the same character set and are all gbk, we can use the following abbreviated form: set names gbk;-- the above sql statement actually contains the following three meanings: set character_set_client=gbk; set character_set_connection=gbk; set character_set_results=gbk Thank you for reading this article carefully. I hope the article "sample Analysis of charset=utf8 in mysql" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.