Mysql Chinese garbled solution _ MySQL

Source: Internet
Author: User
Mysql Chinese garbled detailed solution bitsCN.com


Mysql Chinese garbled solution

This is my previous iteye, which is now placed in it for ease of sorting

I have to do my graduation project recently. I used oracle as my database, and I have never encountered any Chinese garbled characters. However, the graduation designer is out of the field and the laptops are relatively junk. oracle cannot afford them. An eclipse and a Firefox cpu have already run to 90%. So I decided to use the mysql database. Jsp is used at the front end, and UTF-8 is used for encoding.

However, the Chinese garbled characters in mysql have plagued me for a long time. After some queries, we finally solved the problem.

I. check whether the programming environment is UTF-8

Method: Right-click the project name and select UTF-8 for the text file encoding.

II. set the encoding format of the jsp page:

Method: contentType = "text/html; charset = utf-8"

Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"

3. set the encoding formats of request and response:

Methods: response. setContentType ("text/html; charset = utf-8 ");

Request. setCharacterEncoding ("UTF-8 ");

4. compile a filter

V. change the connection method to jdbc: mysql: // localhost/databasename? UseUnicode = true & characterEncoding = UTF-8

After the above five steps, if the problem persists, it may occur on the mysql server.

Database

I. First, check the database character set settings.

Method: set character_set_client = utf8;

In this way, we can see several character sets.

Run the following command to modify

Set character_set_client = utf8;

Set character_set_connection = utf8;

Set character_set_database = utf8;

Set character_set_results = utf8;

Set character_set_server = utf8;

Of course, you can also modify the character set in the mysql installation directory under my. ini in drive C to utf8.

In this step, the data retrieved from the database is basically Chinese, but problems may still occur. for example, when opened in dos, Chinese characters are still garbled, in addition, Chinese characters cannot be inserted with SQL statements in the dos environment.

Set character_set_results = utf8; to set character_set_results = gbk;

Set character_set_client = utf8; set character_set_client = gbk;

In this way, we can basically solve the problem.

BitsCN.com

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.