Character settings in MySQL

Source: Internet
Author: User

MySQL variables related to character sets include


SQL: Show variables like '% character %'

+ -------------------------- + ----------------------------------------------- +
| Variable_name | value |
+ -------------------------- + ----------------------------------------------- +
| Character_set_client | GBK |
| Character_set_connection | GBK |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | GBK |
| Character_set_server | Latin1 |
| Character_set_system | utf8 |
| Character_sets_dir | D: \ Wamp \ bin \ mysql \ mysql5.5.16 \ share \ charsets \ |
+ -------------------------- + ----------------------------------------------- +


The above is all about the character set settings in MySQL. I believe that after understanding the meaning of the above variables, there will no longer be any worries about data garbled characters.

Character_set_client, character_set_connection, character_set_result

These three variables,
Tell the mysql client the replica set, the replica set when it is transmitted to the MySQL server, and the replica set that expects the results returned by MySQL, respectively,

We want to get the correct encoded data. The first of them should have the same encoding set, while the preceding three variable encoding sets have the same shortcut:

Set names utf8

Run the preceding command to set character_set_client, character_set_connection, character_set_result

All three variables are set to UTF-8 encoding,

Then we need to get the data of Positive Solution encoding and know the encoding method of the database, that is, the encoding method set above.
Character_set_database, which is only the default encoding of the database.

We know that the data is stored in tables, so we should use the characters in the table as the benchmark. If the character set of the table is not set, it will inherit the character set of the database.

So if the database is garbled, let's see if the encoding is the same in the above four cases.


In Java, the execution of set names utf8 does not solve the garbled problem. The solution is to change the connection string and specify the character set in the connection string:

Conn = drivermanager. getconnection ("JDBC: mysql: // localhost: 3306/xsgl? Useunicode = true & characterencoding = UTF-8 "," root "," root ");


This character set specifies character_set_client; character_set_connection is UTF-8 encoded, and character_set_results is not specified.
The encoding is null,

So it should be okay to store the database now, but if it is taken out, character_set_results must be encoded the same as the application code (console, Java, etc.).

Http://hi.baidu.com/dburu/blog/item/67b0958bff8b5fdbfd1f108c.html

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.