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