Example of the MySQL Character Set operation procedure

Source: Internet
Author: User
Tags mysql code
The following articles mainly introduce the practical application of the MySQL Character Set, including how to correctly configure the default Character Set of the MySQL database and how to view the MySQL database character set currently used by the database? 1. Configure the MySQL Default Character Set [client] default-character-setutf8 client Connection

The following articles mainly introduce the practical application of the MySQL Character Set, including how to correctly configure the default Character Set of the MySQL database and how to view the MySQL database character set currently used by the database? The following describes the main content of the article. 1. Configure the MySQL default character set [client] default-character-set = utf8 client Connection

The following articles mainly introduce the practical application of the MySQL Character Set, including how to correctly configure the default Character Set of the MySQL database and how to view the MySQL database character set currently used by the database? The following describes the main content of the article,

1. Configure the MySQL Default Character Set

 
 
  1. [client]
  2. default-character-set=utf8

Default MySQL character set for client connection

 
 
  1. [MySQLd]
  2. default-character-set=utf8

MySQLd default Character Set

2. view the MySQL character set currently used by MySQL

 
 
  1. MySQL> show variables like 'character%';
  2. +--------------------------+----------------------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+----------------------------------------+
  5. | character_set_client | utf8 |
  6. | character_set_connection | utf8 |
  7. | character_set_database | utf8 |
  8. | character_set_filesystem | binary |
  9. | character_set_results | utf8 |
  10. | character_set_server | utf8 |
  11. | character_set_system | utf8 |
  12. | character_sets_dir | /usr/local/MySQL/share/MySQL/charsets/ |
  13. +--------------------------+----------------------------------------+

Use the MySQL command to modify the MySQL Character Set

 
 
  1. MySQL> SET character_set_client = utf8 ;
  2. MySQL> SET character_set_connection = utf8 ;
  3. MySQL> SET character_set_database = utf8 ;
  4. MySQL> SET character_set_results = utf8 ;
  5. MySQL> SET character_set_server = utf8 ;

3. C api

 
 
  1. MySQL_options(MySQL, MySQL_SET_CHARSET_NAME, 'utf8');
  2. MySQL_real_connect(MySQL, ...);

In most cases, using the default MySQL code latin1 can solve the MySQL garbled problem. During data insertion and reading, you do not need to use MySQL_options to specify the encoding type. The configuration file my. cnf does not need to specify the encoding type.

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.