High-performance MySQL (7) Character Set and proofing overview

Source: Internet
Author: User
Tags character set mysql

A character set is a mapping from binary encoding to a type of character symbol, and can refer to how to use a byte to represent English.

Proofing refers to a set of collations that are used for a character set.
Each type of encoded character has its corresponding character set and collation rules.

I. How MySQL uses character sets

Each character set may have multiple proofing rules, and all have a default collation rule, and each collation is only related to a character set, and other character sets.

Be sure to keep in mind that only the character set based values are truly the concept of character set.

MySQL's settings can be grouped into two categories:

1, the default value when the object is created

The server has default character set and collation rules, data also has its own default value, each table also has its own default value, this is an inherited default setting, and ultimately depends on the underlying default settings to affect the object you created.

By default:

When you create a database, the default character set for the database is set according to the Character_set_server settings on the server.

When creating a table, specify the character settings for the table according to the database settings.

When you create a column, specify the character set setting for the column, based on the table's settings.

The default of a table is useful only if you create a column that does not specify a character set for the column.

2, the server and client communication settings.

When the client communicates with the server, a different character set may be used, and the necessary transformation is required on the servers side.

If you use Latin1 to open a connection and use the set names UTF8 to tell the server that the client is using UTF-8 to transmit data, some errors may result. You should set the client character set first and use Mysql_set_charset () in PHP to modify the client's character set.

Second, MySQL how to compare the size of 2 strings

If you compare the character sets of 2 strings, MySQL will first convert them to the same character set and then compare them, and if the 2 character sets are incompatible, an error occurs.

Mysql5.0 later versions are implicitly convertible. You can also use prefixes and collate clauses to specify character sets and proofing character sets for strings.

Here's a common principle for us to use:

First select a reasonable character set for the server or database, and then make a column choose its own character set based on the actual situation.

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.