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

Detailed explanation of the mechanism and implementation of accept lock in Nginx

Preface nginx uses a multi-process model. When a ...

A brief analysis of different ways to configure static IP addresses in RHEL8

While working on a Linux server, assigning static...

MySQL derived table (Derived Table) simple usage example analysis

This article uses an example to describe the simp...

Common styles of CSS animation effects animation

animation Define an animation: /*Set a keyframe t...

CentOS 7 installation and configuration method graphic tutorial

This article records the detailed installation tu...

A brief discussion on the CSS overflow mechanism

Why do you need to learn CSS overflow mechanism i...

HTML set as homepage and add to favorites_Powernode Java Academy

How to implement the "Set as homepage" ...

Three Vue slots to solve parent-child component communication

Table of contents Preface Environment Preparation...

Have you really learned MySQL connection query?

1. Inner Join Query Overview Inner join is a very...

JS realizes the card dealing animation

This article example shares the specific code of ...