About the MySQL character set problem (ii)

Source: Internet
Author: User

1. View the default character set (by default, MySQL's character set is Latin1 (Iso_8859_1), and the settings for viewing the system's character set and ordering can be set through the following two commands:
Mysql>SHOW VARIABLES like 'character%';+--------------------------+---------------------------------+|Variable_name|Value|+--------------------------+---------------------------------+|Character_set_client|Latin1||Character_set_connection|Latin1||Character_set_database|Latin1||Character_set_filesystem| binary                          ||Character_set_results|Latin1||Character_set_server|Latin1||Character_set_system|Utf8||Character_sets_dir|D: "MySQL-5.0.Panax Notoginseng"Share" charsets "|+--------------------------+---------------------------------+MySQL>SHOW VARIABLES like 'collation_%';+----------------------+-----------------+|Variable_name|Value|+----------------------+-----------------+|Collation_connection|Utf8_general_ci||Collation_database|Utf8_general_ci||Collation_server|Utf8_general_ci|+----------------------+-----------------+
2. Modifying the default character set  (1) The simplest method of modification is to modify the character set key values in the MySQL My.ini file, such as:
default - character - Set =  =  UTF8
   After the modification, restart the MySQL services, service MySQL restart   using mysql> SHOW VARIABLES like ' character% '; view, found that the database encoding 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|D: "MySQL-5.0.Panax Notoginseng"Share" charsets "|+--------------------------+---------------------------------+
   (2) There is also a way to modify the character set, that is, the command to use MySQL
Mysql> SETCharacter_set_client=UTF8; MySQL> SETCharacter_set_connection=UTF8; MySQL> SETCharacter_set_database=UTF8; MySQL> SETCharacter_set_results=UTF8; MySQL> SETCharacter_set_server=UTF8; MySQL> SETCollation_connection=UTF8; MySQL> SETCollation_database=UTF8; MySQL> SETCollation_server=UTF8;
In general, even if the default character set for the table is UTF8 and the query is sent through UTF-8 encoding, you will find that the database is still garbled. The problem is on the connection connection layer. The workaround is to execute the following sentence before sending the query:
SET ' UTF8 ';
It is equivalent to the following three-sentence instruction:
SET = UTF8; SET = UTF8; SET = UTF8;
Summary: Therefore, the use of what database version, whether it is 3.x, or 4.0.x or 4.1.x, in fact, it is not important to us, it is important to have two:   1) correctly set the database code. MySQL4.0 the following version of the character set is always the default iso8859-1,mysql4.1 when installed will let you choose. If you are ready to use UTF-8, then you must specify a good UTF-8 when you create the database (you can change it after you create it, you can also specify the character set of the table for more than 4.1 versions)   2) Set the database connection encoding correctly. After you have set up the encoding of the database, you should specify the encoding of the connection when you connect to the database, such as when using a JDBC connection, specify the connection as UTF8.

About the MySQL character set problem (ii)

Related Article

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.