MySQL must know must know the study notes Chapter 27 Globalization and Localization

Different languages ​​and character sets need to be stored and retrieved in different ways. MySQL needs to adapt to different character sets, methods of sorting and retrieving data.

Terminology:
1. Character set: a collection of letters and symbols.
2. Encoding: the internal representation of a member of a character set.
3. Proofreading: an instruction specifying how characters are compared.

View the list of character sets supported by MySQL:

SHOW CHARACTER SET;

Run it:
Insert picture description here
This statement shows all available character sets and the description and default collation of each character set.

View the list of supported proofreading:

SHOW COLLATION;

Run it:
Insert picture description here
This statement shows all available collations and their applicable character sets. A character set may have multiple proofreadings. For example, lation1 has proofreading for different European languages, and many proofreadings appear twice, once case-sensitive (represented by _cs) and once case-insensitive (represented by _ci).

Define a default character set and proofreading when the management system is installed. In addition, you can specify the default character set and proofreading of the database when creating the database, and display the character set and proofreading used:

SHOW VARIABLES LIKE 'character%';
SHOW VARIABLES LIKE 'collation%';

Run it: you
Insert picture description here
can specify character sets for different tables and different columns in the table. Specify the character set and collation for the table:

CREATE TABLE tableName
(
    列定义
) DEFAULT CHARACTER SET hebrew
  COLLATE hebrew_general_ci;

If only CHARACTER SET is specified, the default collation of this character set is used. If neither is specified, the default character data and collation of the database are used.

Specify the character set for a column:

CREATE TABLE tableName
(
    column1 INT,
    column2 VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci
) DEFAULT CHARACTER SET hebrew
  COLLATE hebrew_general_ci;

The collation works in the ORDER BY clause. If you need to sort the results of a specific SELECT statement in a different collation order than when the table was created:

SELECT * FROM tableName
ORDER BY columnName COLLATE latin1_general_cs;

The above is case-sensitive proofreading, even when searching on a case-insensitive table. COLLATE can be used in ORDER BY clauses, but also in GROUP BY, HAVING, aggregate functions, and aliases.

Strings can be converted between character sets, just use the Cast or Convert function.

Guess you like

Origin blog.csdn.net/tus00000/article/details/111761562