Character sets and collations
When you connect to the routing endpoint of a database cluster group for Aurora MySQL, your session uses the utf8mb4 character set. The session also uses one of the nine collations that the routing endpoint supports. If your client doesn't ask for a collation, the session uses utf8mb4_0900_ai_ci. That collation is the MySQL default for utf8mb4.
Supported character set and collations
The routing endpoint supports utf8mb4 and the following collations:
utf8mb4_0900_ai_ci(the default)utf8mb4_0900_as_ciutf8mb4_0900_as_csutf8mb4_0900_binutf8mb4_binutf8mb4_general_ciutf8mb4_ja_0900_as_csutf8mb4_ja_0900_as_cs_ksutf8mb4_unicode_ci
Setting the session character set and collation
The routing endpoint accepts only connections that use utf8mb4. Set utf8mb4 explicitly in your client or driver. Each member cluster that your queries reach uses your session collation. The following steps set the character set and collation for a session.
To set the character set and collation for a session
-
Connect to the routing endpoint with
utf8mb4. In the followingmysqlcommand, replacerouting-endpointwith the routing endpoint of your database cluster group for Aurora. Replacerouter-userwith the name of a router user.mysql -hrouting-endpoint-P 3306 -urouter-user-p \ --ssl-mode=REQUIRED --default-character-set=utf8mb4For more information about router users and TLS connections, see Router users and member cluster users and TLS on the routing endpoint.
-
Set the session collation. The following example sets the session collation to
utf8mb4_0900_as_cs:SET NAMES utf8mb4 COLLATE utf8mb4_0900_as_cs;Run
SET NAMESon each new connection that needs a different collation. -
To check the session collation, run the following statement:
SELECT @@collation_connection;The result shows the collation that you set in the previous step.
For more information about character sets, collations, and client configuration, see Character Sets, Collations, Unicode
Collations and string routing keys
The routing layer uses the collation of the scaleout table in the following cases:
When it matches string routing keys for a
COLUMNrouting functionWhen it matches the prefixes that it extracts for a
PREFIXrouting functionWhen it hashes string routing keys with
cityhash,xxhash, ormd5in aHASHrouting function
For more information about routing function syntax, see CREATE SCALEOUT ROUTING FUNCTION.
For the routing functions in the preceding list, 'apple' and 'APPLE' route the same way under the default collation, utf8mb4_0900_ai_ci. Under utf8mb4_bin, 'apple' and 'APPLE' might route to different member clusters. utf8mb4_bin also ignores trailing spaces, so 'm ' routes the same way as 'm'.
If you omit DEFAULT CHARACTER SET and DEFAULT COLLATE from a CREATE SCALEOUT TABLE statement, the scaleout table uses the utf8mb4_0900_ai_ci collation. The scaleout table uses this collation even if the routing key column in the member tables uses another collation. We recommend that you set DEFAULT COLLATE to the collation of the routing key column in the member tables. For more information about the syntax, see CREATE SCALEOUT TABLE.
If the collations differ, the routing layer and the member cluster don't compare values the same way. For example, suppose that a scaleout table uses a COLUMN routing function and the utf8mb4_0900_ai_ci collation. The routing key column in the member tables uses utf8mb4_bin. A query for 'APPLE' reaches the member cluster that stores 'apple', but the query returns no rows.
Listing the supported character set and collations
Connect to the routing endpoint. To list the character set and collations, run SHOW CHARACTER SET and SHOW COLLATION.
Matching character set and collation settings across member clusters
Keep the following settings the same on each member cluster:
The
character_set_serverandcollation_serverparameters. For more information about parameter groups, see Parameter groups for Amazon Aurora.The default character set and collation of each database that is on more than one member cluster.
The character set and collation of each string routing key column in the member tables.
To compare character set and collation settings across member clusters
-
Connect to the cluster endpoint of a member cluster. To show the server, database, and column settings, run the following statements. Replace
member-database-namewith the name of the database on that member cluster. Replacerouting-key-columnwith the name of a string routing key column.SELECT @@GLOBAL.character_set_server, @@GLOBAL.collation_server; SELECT SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'member-database-name'; SELECT TABLE_NAME, COLUMN_NAME, CHARACTER_SET_NAME, COLLATION_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'member-database-name' AND COLUMN_NAME = 'routing-key-column'; -
Repeat the previous step on each member cluster for each string routing key column. Then compare the results. To match each member table across member clusters, use the
TABLE_NAMEcolumn in the results. -
Connect to the routing endpoint. For each scaleout table with a string routing key, run
SHOW CREATE SCALEOUT TABLE. Replacedatabase-name.table-namedatabase-namewith the name of the database that contains the scaleout table. Replacetable-namewith the name of the scaleout table. -
In the output, check that
DEFAULT COLLATEmatches theCOLLATION_NAMEvalue of each string routing key column in the member tables. For more information, see SHOW CREATE SCALEOUT TABLE.
For more information about other settings to check, see Auditing member cluster configuration.