Solution to Chinese garbled characters when operating MySQL database in CMD

Solution to Chinese garbled characters when operating MySQL database in CMD

I searched on Baidu. . Some people say to use the chcp command to change the cmd character encoding to 65001 (utf8 character encoding), but after that, Chinese characters cannot be input at all, and the Chinese query results are still garbled.

In fact, just make sure that the encoding of the cmd client and MySQL is consistent.

But the reality is that cmd defaults to gbk (you can see gbk encoding under the Chinese operating system in cmd properties), and mySQL is generally utf8 (mine is also). I have been making a misunderstanding before and wanted to change the character encoding of cmd, but it didn't work. Netizens mentioned the client encoding problem in MySQL. I just need to tell the MySQL server the client encoding and the desired result set encoding in cmd.

Specific steps:

1. Enter cmd by pressing win+r, and then switch to the bin folder of the MySQL installation directory (or directly open My Computer to find the bin folder and enter cmd in the address bar above);

2. Enter mysql -uroot -p, and then enter the password as prompted to enter the database;

3. Set the encoding;

At this time, enter set character_set_client=gbk; to tell me the text encoding on the client side

Then enter set character_set_results=gbk; to tell MySQL the result set encoding you want to return; in the experiment, it was found that as long as the client is encoded in gbk, setting this can solve the problem of garbled characters.

There is another useful command that can achieve the effect of the above two instructions at the same time:

set charset gbk; // has the same effect as the above two.

Mission accomplished! Try inserting a Chinese field!

PS: Let’s take a look at a simple method below, which can be done with two lines of code!

mysql displays Chinese garbled characters in cmd

The default encoding of cmd is gbk;

Change the character_set_results encoding of mysql to gbk;

set character_set_results = gbk;

Summarize

The above is the solution to the Chinese garbled characters that appear when operating the MySQL database in CMD. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL character set garbled characters and solutions
  • Solution to MySQL garbled code problem under Linux
  • How to solve the problem of Chinese garbled characters when inserting table data into MySQL
  • Solve the problem of Chinese garbled characters when inserting data into MySQL by Tomcat under Linux
  • Summary of handling JDBC connection mysql garbled code exception problem
  • Detailed explanation of the solution to garbled characters when JDBC connects to MySQL to process Chinese
  • Detailed explanation of the Chinese garbled characters problem in MySQL database
  • Solution to the garbled code problem in MySQL 5.x

<<:  One command lets you understand the common parameters of the read command in the shell

>>:  CocosCreator Getting Started Tutorial: Network Communication

Recommend

Detailed description of the function of new in JS

Table of contents 1. Example 2. Create 100 soldie...

Learn MySQL index pushdown in five minutes

Table of contents Preface What is index pushdown?...

Three common style selectors in html css

1: Tag selector The tag selector is used for all ...

Native JS to implement real-time clock

Share a real-time clock effect implemented with n...

Vue implements simple calculator function

This article example shares the specific code of ...

Simple use of Vue bus

Simple use of Vue bus Scenario description: Compo...

Introduction to the use of HTML element noscript

noscript definition and usage The noscript elemen...

How to Install and Configure Postfix Mail Server on CentOS 8

Postfix is ​​a free and open source MTA (Mail Tra...

Nginx http health check configuration process analysis

Passive Check With passive health checks, NGINX a...

A brief talk about the diff algorithm in Vue

Table of contents Overview Virtual Dom principle ...

Tomcat+Mysql high concurrency configuration optimization explanation

1.Tomcat Optimization Configuration (1) Change To...

Dynamic SQL statement analysis in Mybatis

This article mainly introduces the dynamic SQL st...

Detailed analysis of MySQL optimization of like and = performance

introduction Most people who have used databases ...

WeChat applet implements calculator function

WeChat Mini Programs are becoming more and more p...