MySQL character set _ MySQL

Source: Internet
Author: User
MySQL Character Set Support has two aspects:

Character set and Collation ).

The support for character sets is refined to four layers:

Server, database, table, and connection ).

1. default character set of MySQL

MySQL can refine the character set designation to a database, a table, and a column.

However, traditional programs do not use such complex configurations when creating databases and data tables. they use the default configuration. So where does the default configuration come from?

(1) when compiling MySQL, a default character set is specified, which is latin1;

(2) when installing MySQL, you can specify a default character set in the configuration file (my. ini). If this character set is not specified, this value inherits from the one specified during compilation;

(3) when mysqld is started, you can specify a default character set in the command line parameters. if not, this value inherits from the configuration in the configuration file, character_set_server is set to the default character set;

(4) when creating a new database, unless explicitly specified, the character set of this database is set to character_set_server by default;

(5) when a database is selected, character_set_database is set to the default character set of the database;

(6) when creating a table in the database, the default character set of the table is set to character_set_database, which is the default character set of the database;

(7) when setting a column in a table, unless explicitly specified, the default character set in this column is the default character set of the table;

Simply put, if you do not modify anything, all the columns of all tables in all databases will be stored in latin1. However, if you install MySQL, you will generally choose multi-language support, that is, the installer automatically sets default_character_set in the configuration file as a UTF-8, which ensures that all columns of all tables in all databases are stored in UTF-8 by default.

2. view the default character set. (by default, the mysql character set is latin1 (ISO_8859_1)

Generally, you can run the following two commands to view the character set and sorting method of the system:

Mysql> SHOWVARIABLESLIKE '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.37" share "charsets" |
+ -------------------------- + ----------------------------------- +
Mysql> SHOWVARIABLESLIKE 'collation _ % ';
+ ---------------------- + ----------------- +
| Variable_name | Value |
+ ---------------------- + ----------------- +
| Collation_connection | utf8_general_ci |
| Collation_database | utf8_general_ci |
| Collation_server | utf8_general_ci |
+ ---------------------- + ----------------- +

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.