Specifying Character Set and Collation for Clusters

Setting Character Set and Collation Engine Variables

Specify the character set for the cluster by setting the character_set_server engine variable.

Specify the collation for the cluster by setting one of the collation_connection, collation_database, and collation_server engine variables.

Important

Although these variables are session variables, these variables must be set globally to avoid undesired behavior. If one of these variables is set in a session to a value that does not match the value set globally, an error is generated. Change the value globally first, then change it in the session to match.

character_set_server

Controls the default character set of the cluster. Can be set to utf8mb4, utf8, or binary.

If character_set_server is set to a value that is different from its previous value, the associated collation variables collation_connection, collation_database, and collation_server are set to that character set’s default collation.

collation_connection, collation_database, and collation_server

Controls the default collation of the cluster. Can be set to the values returned by the SHOW COLLATION command.

When any of the collation_connection, collation_database, and collation_server, variables are set, the other two variables are set to the same value and the collation is applied to the nodes.

In addition, when any of these three variables is set, the variable character_set_server is set to a value that corresponds to the collation.

Set character_set_server

To set the character_set_server variable cluster-wide, use the following instructions.

Using a SingleStore client, run SET CLUSTER (the equivalent of SET GLOBAL) to set the character_set_server variable across the cluster. For example:

SET CLUSTER character_set_server = 'utf8';
Query OK, 0 rows affected (0.03 sec)

If the character_set_server variable is set using SET CLUSTER (or its equivalent SET GLOBAL) or SET AGGREGATOR, additionally run FLUSH CONNECTION POOLS on every aggregator node and restart the SQL session for the new value to take effect.

SingleStore offers commands to set engine variables cluster-wide, on all aggregator nodes, or on leaf nodes. Refer to Sync Variables and Engine Variables for more information.

Set collation_connection, collation_database, and collation_server

To set the collation variables cluster-wide, use the following instructions.

Using a SingleStore client, run SET CLUSTER (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)

If a collation variable is set using SET CLUSTER (or its equivalent SET GLOBAL) or SET AGGREGATOR, additionally run FLUSH CONNECTION POOLS on every aggregator node and restart the SQL session for the new value to take effect.

SingleStore offers commands to set engine variables cluster-wide, on all aggregator nodes, or on leaf nodes. Refer to Sync Variables and Engine Variables for more information.

Warning

The following SingleStore engine variables exist for backwards compatibility with MySQL and are non-operational in SingleStore. These variables are available for read only; they are not available for write.

  • character_set_client

  • character_set_connection

  • character_set_database

  • character_set_filesystem

  • character_set_results

  • character_set_system

  • character_sets_dir

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 Example

The following example shows that utf8_general_ci collation is case-insensitive. The output is 1, indicating that A and a match in this collation.

SET collation_connection = 'utf8_general_ci';
SELECT 'A' = 'a';
+-----------+
|'A' = 'a'  |
+-----------+
| 1         |
+-----------+

The following example shows that utf8_bin collation is case-sensitive. The output is 0, indicating that A and a do not match in this collation.

SET collation_connection = 'utf8_bin';
SELECT 'A' = 'a';
+-----------+
|'A' = 'a'  |
+-----------+
| 0         |
+-----------+

Important

Among the collations supported for the utf8mb4 character set, SingleStore recommends utf8mb4_unicode_ci for accurate comparison and sorting of characters, especially when using characters from non-English international languages. While utf8mb4_general_ci improves the performance of comparing and sorting operations, the results may not be precise when using certain language characters.

Last modified:

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK

Try Out This Notebook to See What’s Possible in SingleStore

Get access to other groundbreaking datasets and engage with our community for expert advice.