当前位置:网站首页>MySQL client to server character set conversion
MySQL client to server character set conversion
2022-07-24 00:22:00 【Java interview 365】
Mysql Client to server character set conversion
Mysql The communication request between the client and the server is essentially a string , Of course, this string will be converted into binary data through some character set encoding , Is there only one character set code for the communication between the client and the server ? As shown below

Server code
Obviously not , The conversion of three character sets is involved in the process of the server processing the request , These three transformations correspond to three system variables respectively, as shown below
**
character_set_client**: The character set used by the server to decode the string requested by the client .**
character_set_connection**: When the server processes the request, it willcharacter_set_clientConvert character set tocharacter_set_connectionCharacter set .**
character_set_results**: The character set code used when the server returns to the client .
View the character set as follows
### For space , Directly use fuzzy query to view , The character set is shown below
mysql> show variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.26/share/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.00 sec)
Client code
And if the client sends a request, it will encode the string into binary data according to the character set of the operating system , After receiving the request from the server, the client will also decode the binary data into a string according to the character set of the operating system , How to check the character set of the operating system ?
### stay /etc/locale.conf file centos8 The default character set is configured as follows
[[email protected] ~]# cat /etc/locale.conf
LANG=en_US.UTF-8
The conversion process
The conversion process involves the conversion of several character sets , Steps are as follows
The client adopts the system character set, and the default is UTF8 Encode the operation database statement , Become binary data , This is limited to
mysql -uroot -pxxxAccess client , It does not include popular graphical interface clients such as Navicat,DBeaver etc. .After the server receives the binary data sent by the client , Through the character set
character_set_clientCharacter set decoding , Change to string .Use the decoded string
character_set_connectionCharacter set encoding , Become binary data for operating the database , If the character set of the database column andcharacter_set_connectionCharacter sets are different , Then you need to convert the character set , Finally get the result data .Before returning to the client, you also need to send the result according to
character_set_resultsEncoding .The client receives the returned binary data , It also needs to decode according to the system character set , Finally displayed on the client .
Convert the above file into a flowchart , As shown below

Character set modification
The system variables of the server related character set are three , If you want to modify it, you generally need to modify it synchronously in order to ensure that it will not be garbled , Obviously, this is troublesome , Then we can adopt the following two ways , The effect of these two methods is to update the three system variables related to the server code at one time .
set The way
Use combined commands set names Character set name , The command is demonstrated as follows
mysql> show variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.26/share/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%character%';
+--------------------------+-----------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.26/share/charsets/ |
+--------------------------+-----------------------------------------+
8 rows in set (0.01 sec)
Modify the configuration file
In the default configuration file /etc/my.cnf, Add client startup system configuration parameters
[client]
default-character-set=gbk
Reconnect the client to get the modified character set , Effect and set similar .
边栏推荐
- Application of encryption technology
- Gbase 8C access authority access function (IV)
- Detectron2 installation based on Anaconda under win10
- 蓝绿部署、金丝雀发布、A/B测试是什么
- The name in Qiankun subapplication package.json becomes the default path
- Educational Codeforces Round 132 (Rated for Div. 2)(A-D)
- Tencent will close the "magic core". Is there any resistance to the development of digital collections?
- IIS deployment.Netcore
- Take stock of 10 new layer1 to prepare for the next bull market
- Multi data source configuration of mongodb
猜你喜欢

Xmind用例导入到TAPD的方案(附代码)

YOLOv1

数仓数据指标和标签体系区别

数据模型设计方法概述

iNFTnews | 呵护“雪山精灵”,42VERSE“数字生态保护”公益项目即将盛启

English语法_指示代词 -such / the same

Delete all data of specified query criteria in Oracle

paypal订阅流程及api请求

Mobile terminal H5 - a lifeline timeline
![[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)](/img/b5/dd4316b83ef4b80c36b532de658bb2.png)
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
随机推荐
Redis cluster construction (cluster cluster mode, fragment cluster)
GBase 8c模式可见性查询函数(二)
北峰通信亮相中国(厦门)应急展|智能化通信手段强势吸睛!
Docker pulls the redis image and runs it
Redis分布式锁待续
投资的物质回报
Tencent cloud was affirmed by international professional streaming media evaluation: video coding performance is the best in all three scenarios
进步成长的快乐
Redis 集群hash分片算法(槽位定位算法)
Delete all data of specified query criteria in Oracle
作为一个程序员,有什么想对新人说的吗?
【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)
Summarize the plan, clarify the direction, concentrate and start a new situation -- the Counterpart Assistance Project of hexu software has achieved remarkable results
自己喜欢投资
English grammar_ Demonstrative pronoun - so
Gbase 8C system table information function (III)
The universal esp32c3 configures partition tables based on the Arduino ide framework
Gbase 8C session information function (6)
【译】Go RPC 入门:Hello World
Multi data source configuration of mongodb