Specifying Character Set and Collation for Clusters
On this page
Setting Character Set and Collation Engine Variables
You can specify the character set and collation for your cluster by setting the following engine variables.
-
character_
set_ server: The character set of the entire cluster that can be set to utf8mb4
,utf8
, orbinary
.If you set character_
to a value that is different from its previous value, SingleStore sets the associated collation variables collation_set_ server connection, collation_ database, and collation_ server to the character set’s default collation. To set the
character_
variable cluster-wide, follow the instructions below.set Warning
Although the
character_
variable is a session variable, you must set the variable globally to avoid undesired behavior.set_ server An error is generated if the variable is set in a session to a value that does not match the value set globally. Change the value globally first, then change it in the session to match. -
Using a SingleStore client, run
SET CLUSTER
(which is the equivalent ofSET GLOBAL
) to set thecharacter_
variable across the cluster.set_ server For example: SET CLUSTER character_set_server = 'utf8';Query OK, 0 rows affected (0.03 sec)
Note: SingleStore offers alternative commands to set engine variables.
See Sync Variables for more information. -
If you set the
character_
variable usingset_ server SET CLUSTER
(or its equivalentSET GLOBAL
)orSET AGGREGATOR
, you need to additionally run FLUSH CONNECTION POOLS on every aggregator node and restart the SQL session for the newcharacter_
value to take effect.set_ server
-
-
collation_
connection, collation_ database, and collation_ server: These are the collation variables that are set cluster-wide, or on all aggregator nodes or leaf nodes depending on how you set the engine variables. These variables can take the collations returned by the SHOW COLLATION
command as values.When you set any of collation_
,connection collation_
, anddatabase collation_
, SingleStore sets the other two variables to the same value and applies the collation to the nodes.server Also, when you set any of these three variables, SingleStore sets character_ set_ server to a value that corresponds to the collation configured. To set the collation variables cluster-wide, follow the instructions below.
Warning
Although the collation variables are session variables, you must set the variable globally to avoid undesired behavior.
An error is generated if any of these variables is set in a session to a value that does not match the value set globally. Change the value globally first, then change it in the session to match. -
Using a SingleStore client, run
SET CLUSTER
(which is the equivalent of SET GLOBAL) to set the collation variable across the cluster.For example: SET CLUSTER collation_server = 'utf8_general_ci';Query OK, 0 rows affected (0.03 sec)
Note: SingleStore offers alternative commands to set engine variables.
See Sync Variables for more information. -
If you set the character_
set_ server variable using SET CLUSTER
(or its equivalentSET GLOBAL
) orSET AGGREGATOR
, you need to additionally run FLUSH CONNECTION POOLS on every aggregator node and restart the SQL session for the new collation value to take effect.
-
To set a collation cluster-wide, issue the following command.
SET CLUSTER collation_server = 'utf8_general_ci';
Query OK, 0 rows affected (0.03 sec)
Alternatively, you can use SET AGGREGATOR
or SET LEAF
to sync the collation variable to the respective nodes.
Reading Character Set and Collation Engine Variables
To retrieve values of the character set or the collation in current use, use the @@
selector with the required variable in a SELECT
statement.
SELECT @@collation_server;
+--------------------+
| @@collation_server |
+--------------------+
| utf8mb4_general_ci |
+--------------------+
1 row in set (0.00 sec)
Collation Demonstration
The following example shows that utf8_
collation is case-insensitive.
SET collation_connection = 'utf8_general_ci';SELECT 'A' = 'a';
The following example shows that utf8_
collation is case-sensitive.
SET collation_connection = 'utf8_bin';SELECT 'A' = 'a';
Important
Among the collations supported for the utf8mb4
character set, utf8mb4_
is recommended for accurate comparison and sorting of characters, especially when using characters from non-English international languages.utf8mb4_
improves the performance of comparing and sorting operations, the results may not be precise when using certain language characters.
Last modified: August 29, 2024