Example tutorial for solving Java program with garbled parameters when using Mysql _mysql

Source: Internet
Author: User

First of all, MySQL's character set problem. Windows can be modified by modifying the My.ini within the

Default-character-set=utf8  //client's default character set

Enter in the MySQL client tool

 
 

Shows the following

This performs read information returned to Chinese as garbled, the solution is, after connecting the database, read the data, first execute a query SET NAMES ' UTF8 '; can be displayed correctly.

The simplest and most perfect way to modify the character set key values in the MySQL my.cnf file (note the details of the configured fields):

1. Add Default-character-set=utf8 to the [client] field as follows:

Port = 3306 
socket =/var/lib/mysql/mysql.sock 
Default-character-set=utf8 

2. Add the Character-set-server=utf8 in the [mysqld] field as follows:

Port = 3306 
socket =/var/lib/mysql/mysql.sock 
Character-set-server=utf8 

3, in the [MySQL] field to add Default-character-set=utf8, as follows:

No-auto-rehash 
Default-character-set=utf8 

After the modification is complete, the service MySQL restart restart MySQL services will take effect. Note: The [mysqld] field differs from the [MySQL] field. No one has been feedback on the Internet.

Use show VARIABLES like ' character% '; Check to see that the database code has been changed to UTF8.

+--------------------------+----------------------------+ 
| variable_name | Value | 
+--------------------------+----------------------------+ 
| character_set_client | utf8 | 
| character_set_connection | UTF8 | 
| Character_set_database | UTF8 | 
| Character_set_filesystem | binary | 
| Character_set_results | UTF8 | 
| Character_set_server | UTF8 | 
| Character_set_system | UTF8 | 
| Character_sets_dir | /usr/share/mysql/charsets/| 
+--------------------------+----------------------------+ 


4, if the above are all modified also garbled, the remaining problems must be on the connection connection layer. The workaround is to execute the following sentence (written directly at the front of the SQL file) before sending the query:

SET NAMES ' utf8′; 

It corresponds to the following three-sentence instruction:

SET character_set_client = UTF8; 
SET character_set_results = UTF8; 
SET character_set_connection = UTF8; 


Many other methods on the Internet can not completely solve this problem, this could be a perfect solution!

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.