When you migrate or merge the databases of an ApsaraDB RDS for MySQL instance, if the character sets and character collations of the databases are incompatible or the supporting applications have special requirements for character sets and character collations, you can modify the character_set_server and collation_server parameters of the RDS instance.
Background information
The character_set_server parameter specifies the default character set of an RDS instance. The collation_server parameter specifies the collation of the character set.
A character set supports various collations. For example, the UTF-8 character set supports the utf8_general_ci and utf8_bin collations. The Latin-1 character set supports the latin1_general_ci and latin1_bi collations. A character set collation specifies how characters in a character set are compared and sorted.
Collations are categorized into two types: binary collation and language-specific collation.
A binary collation, such as
utf8_bin, compares the binary values of characters regardless of the language environments and case sensitivity of the characters. For example, the binary values of charactersaandAare different. As a result, they are considered different characters and are sorted based on their binary values. A binary collation sorts characters at a high speed but may not comply with the language behavior.A language-specific collation, such as
utf8_general_ci, takes the language environments and case sensitivity of characters into consideration. For example, charactersaandAare considered the same. As a result, a sorting result that complies with the language behavior can be obtained.
In MySQL, character_set_server and collation_server are associated because collations are character set-specific. Different character sets support different collations. Only character sets and collations that are compatible with each other can be used in combination.
In MySQL,
utf8andutf8mb3are aliases for each other and specify the same character set.utf8mb3is the alias that distinguishes fromutf8mb4. In MySQL 5.7 and later versions, we recommend that you use theutf8mb4character set as the default character set to support more characters. In some scenarios, such as tests on compatibility with code or databases in earlier versions of MySQL, you still need to use theutf8orutf8mb3character set.You can set the
character_set_serverandcollation_serverparameters only toutf8instead ofutf8mb3.
Notes
You can modify the character_set_server and collation_server parameters only on the primary RDS instance but not read-only instances.
Parameter setting rules
If you modify only the
character_set_serverparameter, the system automatically sets thecollation_serverparameter to the default value that matches thecharacter_set_serverparameter regardless of the current value of thecollation_serverparameter. For example, if you set thecharacter_set_serverparameter toutf8, the system automatically changes the value of thecollation_serverparameter toutf8_general_ci.Noteutf8andutf8mb3are aliases for each other. As a result, theutf8_general_ciandutf8mb3_general_cicollations are the same. When you set thecharacter_set_serverparameter toutf8, the value of thecollation_serverparameter may be changed toutf8mb3_general_ci.If you modify only the
collation_serverparameter, the system checks whether the new value of the parameter matches the value of thecharacter_set_serverparameter. If the values of the parameters do not match, you cannot modify thecollation_serverparameter. For more information, see Parameter values.If you modify the
character_set_serverandcollation_serverparameters at the same time, the system checks whether the new values of the parameters match. If the new values do not match, you cannot modify the parameters. For more information, see Parameter values.You can set the
character_set_serverandcollation_serverparameters only to the values that are listed in the tables in Parameter values.
When you create or modify a custom parameter template, you must take note of the following items:
If you modify only the
character_set_serverparameter, the default value is used for thecollation_serverparameter.If you modify the
character_set_serverandcollation_serverparameters at the same time, make sure that the new values of the parameters meet the parameter setting rules.
Parameter values
Default values
MySQL version | character_set_server | collation_server |
MySQL 8.0, MySQL 5.7, and MySQL 5.6. | utf8 | utf8_general_ci |
Parameter matching
The minor engine version of the RDS instance must meet one of the following requirements:
If your RDS instance runs MySQL 8.0, the minor engine version must be 20200331 or later.
If your RDS instance runs MySQL 5.7, the minor engine version must be 20181226 or later.
If your RDS instance runs MySQL 5.6, the minor engine version must be 20221130 or later.
character_set_server | collation_server | Default value of collation_server | Description |
utf8 | utf8_general_ci | Yes | The parameter matching is the same for RDS instances that run MySQL 8.0, MySQL 5.7, and MySQL 5.6. |
utf8_bin | No | ||
utf8_unicode_ci | No | ||
utf8_unicode_520_ci | No | ||
utf8_general_mysql500_ci | No | ||
latin1 | latin1_swedish_ci | Yes | The parameter matching is the same for RDS instances that run MySQL 8.0, MySQL 5.7, and MySQL 5.6. |
latin1_bin | No | ||
latin1_general_ci | No | ||
latin1_general_cs | No | ||
gbk | gbk_chinese_ci | Yes | The parameter matching is the same for RDS instances that run MySQL 8.0, MySQL 5.7, and MySQL 5.6. |
gbk_bin | No | ||
gb18030 | gb18030_chinese_ci | Yes | The parameter matching is the same for RDS instances that run MySQL 8.0 and MySQL 5.7. gb18030 is not supported for RDS instances that run MySQL 5.6. |
gb18030_bin | No | ||
gb18030_unicode_520_ci | No | ||
utf8mb4 | utf8mb4_0900_ai_ci | Yes | The collations are supported only for RDS instances that run MySQL 8.0 but are not supported for RDS instances that run MySQL 5.7 and MySQL 5.6. |
utf8mb4_0900_as_ci | No | ||
utf8mb4_0900_as_cs | No | ||
utf8mb4_0900_bin | No | ||
utf8mb4_general_ci |
| None. | |
utf8mb4_bin | No | The parameter matching is the same for RDS instances that run MySQL 8.0, MySQL 5.7, and MySQL 5.6. | |
utf8mb4_unicode_520_ci | No | ||
utf8mb4_unicode_ci | No |