How to Globally Set Collation utf8mb4_general_ci in TIDB 6.0

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TIDB 6.0如何全局设置排序规则utf8mb4_general_ci

| username: TiDB_New_People

How to globally set the collation to utf8mb4_general_ci in TIDB 6.0?
The new collation rule is enabled by default.

| username: hey-hoho | Original post link

CREATE DATABASE db_name CHARACTER SET utf8mb4_general_ci

| username: ddhe9527 | Original post link

It should be the same as MySQL. Try the system variable collation_server.

| username: TiDB_New_People | Original post link

The database has already been built, upgraded from TiDB 5.3 to 6.1.

| username: TiDB_New_People | Original post link

Teacher, could you explain in more detail? Is it the command set collation_server=utf8mb4_general_ci? I tried it, but it didn’t work.

| username: ddhe9527 | Original post link

set global collation_server=utf8mb4_general_ci;
If the collation is not specified when creating the database, it will use this collation to create the database. If the database has already been created, then if the collation is not specified when creating a table, it will inherit the collation of the database.

| username: db_user | Original post link

Currently, TiDB cannot set the character set and collation globally; it can only be specified at the database level. This should be considered a bug. For more details, you can refer to this issue: create database should use `collation_server` collation if it not specified · Issue #23199 · pingcap/tidb · GitHub

| username: ddhe9527 | Original post link

No issues found in v5.4.0 testing.

| username: db_user | Original post link

Indeed, I tested it on page 5.4.1 and there was no issue. So, this problem can be resolved by setting it globally. It’s strange why the issue hasn’t been closed.

| username: cs58_dba | Original post link

Yes, it’s similar to MySQL.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. No new replies are allowed.