When MySQL inserts the data, the Chinese garbled problem solves

Source: Internet
Author: User

when inserting a data form with Chinese into the MySQL database such as INSERT into employee values (null, ' Zhang San ', ' female ', ' 1995-10-08 ', ' 2015-11-12 ', ' Sales ', 2000, ' is a good employee! '); When garbled, you can use the statement show variables like ' character% ' to view the relevant encoding set for the current database.

you can see that MySQL has six character sets used in the following: client, connection, database, results, server, System. The server-side Related: Database, server, System (can never be modified, is utf-8); related to clients: Connection, client, results.
Client The character set used for the client.
Connection Sets the type for the character set of the connection database, if the program does not indicate that the character set type used by the connection database is set according to the default set of characters on the server side.
Database The character set that is used for a library in the database server, and if it is not specified when the library is built, uses the charset settings specified when the server is installed.
Results The character set that is used when the database is returned to the client and, if not specified, the default character set of the server.
Server The default character set specified when the server is installed.
System The character set used for the database system.
understand the above information we come to analyze the reason for garbled, the problem is in the current CMD client window, because the current CMD client input using GBK encoding, and the database encoding format is UTF-8, encoding inconsistency led to garbled production. And the current CMD client encoding format can not be modified, so can only modify the connection, client, results encoding set to inform the server side of the current data inserted GBK encoding, and the server database, although the use of UTF-8 encoding, But it can recognize the GBK encoded data on the notification server side and automatically convert it to UTF-8 for storage. You can use the following statement to quickly set up the encoding set associated with the client:
    • Set names GBK;

After the setting is complete, the client can be resolved to insert data or display data garbled problem, but we will soon find that this form of settings only in the current window is valid, when the window is closed and reopen the CMD client when the garbled problem will occur, then, how to do a once and for all settings? In the MySQL installation directory has a my.ini configuration file, by modifying this configuration file can once and for all solve garbled problem. In this configuration file [MySQL] is related to the client configuration, [mysqld] is related to the server configuration.

the values for Default-character-set and character-set-server are then changed to UTF8 , restart the MySQL service.

--

Reprinted from:

Http://www.cnblogs.com/sunzn/archive/2013/03/14/2960248.html

When MySQL inserts the data, the Chinese garbled problem solves (turns)

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.