A Chinese garbled solution occurs when you operate mysql Databases in CMD.

Source: Internet
Author: User

A Chinese garbled solution occurs when you operate mysql Databases in CMD.

Baidu .. It is said that the chcp command is used to change the cmd character encoding to 65001 (utf8 character encoding). After that, Chinese characters cannot be entered, and the query results are still garbled.

In fact, you only need to ensure that the cmd client and MySQL are both encoded in the same way.

However, the reality is that the default value of cmd is gbk (the cmd attribute can be seen below the Chinese operating system is gbk encoding), while mySQL is generally utf8 (which is also mine), which has been a misunderstanding, it does not work if you want to change the character encoding of cmd. Users mentioned about client encoding in mysql. Just tell the mysql server in cmd about the encoding of the client and the desired result set.

Procedure:

1. win + r go to cmd and switch to the bin folder in the mysql installation directory (or open my computer to find the bin folder and Enter cmd in the address bar above );

2. Enter mysql-uroot-p and enter the password as prompted to be included in the database;

3. Set the encoding;

Enter set character_set_client = gbk; tell me the text encoding on the client side

Enter set character_set_results = gbk to tell mysql to return the result set encoding. In the experiment, we found that as long as the client is gbk encoded, we only need to set this to solve the Garbled text problem.

Another useful command can achieve the effects of the above two commands at the same time:

Set charset gbk; // The effect is the same as that of the preceding two.

Success! Try inserting Chinese fields!

PS: Let's look at a simple method. Let's get it done with two lines of code!

Mysql displays Chinese garbled characters in cmd

The default cmd encoding is gbk;

Modify the character_set_results encoding of mysql to gbk;

set character_set_results = gbk;

Summary

The above is a small Editor to introduce the Chinese garbled solution for operating mysql Databases in CMD. I hope it will help you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.