View and solve Chinese garbled characters in MySQL Databases

Source: Internet
Author: User
Chinese garbled characters in MySQL databases have been a problem for a long time, whether it is java Development or php development.

Chinese garbled characters in MySQL databases have been a problem for a long time, whether it is java Development or php development.

Chinese garbled characters in MySQL databases have been a problem for a long time, whether it is java Development or php development.

For the sake of simplicity, I have always set the encoding to UTF-8 on all my JSP pages. At the same time, when I create a MySQL database, I also set it to UTF-8 encoding ,, to prevent inexplicable Chinese garbled characters. However, today we have found a simpler method, without looking into the cause, but it can quickly diagnose and solve Garbled text. (There is no possibility of testing, just generalize)

1. If you find that the Chinese characters inserted in the database are garbled characters on the MySQL console, you can run the "status" command to view the status of the current MySQL database. In the query results, there are several character encoding-related items:

Server characterset: utf8 -- install the MySQL Server as the configured Server code
Db characterset: utf8 -- default database Encoding
Client characterset: utf8 -- Client character encoding
Conn. characterset: utf8 -- encoding used for connection

2. On the MySQL console, use the following command to change the character encoding of the last two items:

Set names gb2312

Then run the "status" command to check whether the encoding of the last two items has changed to "gb2312.

3. query the database again and find that the garbled characters are missing. The Chinese characters are clearly displayed in the database.

4. vice versa. If the last two encoding types are gb2312 in case of Chinese garbled characters, use "set names utf8" and change it to "utf8" encoding.

Please remember!

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.