Detailed explanation of encoding issues during MySQL command line operations

Detailed explanation of encoding issues during MySQL command line operations

1. Check the MySQL database encoding

mysql -u username -p password show variables like 'char%'; 

2. Coding explanation

1. character_set_client: MySQL will use this encoding to interpret the data sent by the client. If the field is encoded as utf8, then if the data sent by the client is not utf8, garbled characters will appear.

2. character_set_results: MySQL will convert the data into this encoding before sending it to the client. For example, if the encoding is utf8, then if the client does not use utf8 to interpret it, garbled characters will appear.

3. Console garbled characters

3.1 Garbled characters appear when inserting or modifying

Reason: The cmd command line uses gbk encoding by default, but character_set_client is utf8.

solve:

set character_set_client = gbk;

3.2 The queried data is garbled

Reason: The cmd command line uses gbk encoding by default, but set character_set_results is utf8.

solve:

set character_set_results = gbk;

4. Specify the default encoding

The above solution is only valid for the current connection. When you exit the window, you need to set the variable again when you log in to MySQL again. Therefore, in order to solve the problem once and for all, we can set it in my.ini under the MySQL installation directory :

Just change it to gbk:

See the effect:

At this point, our MySQL encoding problem in command line operations has been successfully solved~!

Summarize

This is the end of this article about the detailed explanation of encoding issues during MySQL command line operations. For more relevant MySQL command line operation encoding content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the problem that MySQL commands cannot be entered in Chinese
  • Introduction to the use of MySQL source command
  • MySQL commonly used SQL and commands from entry to deleting database and running away
  • Implementation of mysql using mysqlbinlog command to restore accidentally deleted data
  • Introduction to query commands for MySQL stored procedures
  • Three methods of automatically completing commands in MySQL database
  • MySQL password contains special characters & operation of logging in from command line
  • Mysql desktop tool SQLyog resources and activation methods say goodbye to the black and white command line
  • MySQL login and exit command format
  • How to use the MySQL authorization command grant
  • Summary of MySQL basic common commands

<<:  Design theory: people-oriented green design

>>:  An example of the calculation function calc in CSS in website layout

Recommend

Linux installation MySQL5.6.24 usage instructions

Linux installation MySQL notes 1. Before installi...

10 Best Practices for Building and Maintaining Large-Scale Vue.js Projects

Table of contents 1. Use slots to make components...

Ajax responseText parses json data case study

Solve the problem that the responseText returned ...

Should the Like function use MySQL or Redis?

Table of contents 1. Common mistakes made by begi...

Solve the problem of VScode configuration remote debugging Linux program

Let's take a look at the problem of VScode re...

MySQL trigger principle and usage example analysis

This article uses examples to explain the princip...

CSS3 realizes draggable Rubik's Cube 3D effect

Mainly used knowledge points: •css3 3d transforma...

Introduction to NFS service construction under Centos7

Table of contents 1. Server 2. Client 3. Testing ...

MySQL 5.7.30 Installation and Upgrade Issues Detailed Tutorial

wedge Because the MySQL version installed on the ...

MySQL date and time addition and subtraction sample code

Table of contents 1.MySQL adds or subtracts a tim...

Vue implements the shake function (compatible with ios13.3 and above)

Recently, I made a function similar to shake, usi...

How to install and connect Navicat in MySQL 8.0.20 and what to pay attention to

Things to note 1. First, you need to create a my....