Convert utf8 to gbk

Source: Internet
Author: User
Convert utf8 to gbk utf8 to gbk

Use the set names character set
Character_set_connection these three items are set as set names gbk in the cmd black window; at that time, the data file layer and the system management layer are utf8. during The cmd window query, the data is retrieved from the file and passed through the data management layer and then to character_set_result. in this process, there should be encoding conversion problems. convert from utf8 to gbk? Then, if this conversion happens, there should be garbled characters.

Reply to discussion (solution)

Yes, and your file code must be gbk.

If you use cmd to directly connect to the mysql client, mysql automatically converts

If you execute php in cmd, the output depends on the php file encoding.

From the database to php is an IO, and from php echo to cmd is also an IO. pay attention to the encoding changes before and after the two IO

You said that cmd should be windows. windows cmd follows the system encoding by default. for example, for windows in simplified Chinese, cmd uses cp936 (equivalent to gbk) encoding by default, this encoding can be changed permanently through the registry, or temporarily using the "chcp xxx" command, where xxx is the encoding number, 936 is equivalent to gbk, 65001 is equivalent to UTF-8

At the beginning of cmd, enter chcp 65001 and press Enter. the cmd window is equivalent to UTF-8 encoding output.

Note: cpxxx is a Microsoft-defined code, which is slightly different from the corresponding general-purpose code. Generally, these differences are not involved in use, so the above statements are "equivalent"

I learned to add my favorite to my favorites.

As long as your data field connection proofreader is a Chinese series (gbk, big5, utf8, UCS-2, UTF-16 ....)
In this case, you only need to set the names character set, and then you can operate according to the character set you need.
Mysql completes code conversion for you.

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: 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.