pingcap / pingcap/tidb

Compatible with mysql support change default collation for utf8mb4

Open
#45,455 3 comments 0 reactions 0 assignees View on GitHub
compatibility-mysql80 sig/sql-infra type/compatibility type/feature-request
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Feature Request

**Is your feature request related to a problem? Please describe:**

Mysql 8.0 support change default collation for utf8mb4.If we create table with DEFAULT CHARSET=utf8mb4,but did not specify collation, so the value of collation is inherited from default_collation_for_utf8mb4.But tidb doesn't support it yet.

**Describe the feature you'd like:**

TiDB should support default_collation_for_utf8mb4 variable let user can change the default collation for utf8mb4.
```
mysql> SELECT @@GLOBAL.collation_database,@@SESSION.collation_database;
+-----------------------------+------------------------------+
| @@GLOBAL.collation_database | @@SESSION.collation_database |
+-----------------------------+------------------------------+
| utf8mb4_general_ci | utf8mb4_general_ci |
+-----------------------------+------------------------------+
1 row in set (0.00 sec)

mysql> create database sbtest1 /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
Query OK, 1 row affected (0.09 sec)

mysql> use sbtest1;
Database changed
mysql> create table t3 (id int) DEFAULT CHARSET=utf8mb4 ;
Query OK, 0 rows affected (0.02 sec)

mysql> show create table t3;
+-------+--------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (
`id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+--------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> set session default_collation_for_utf8mb4='utf8mb4_general_ci';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show variables like '%collation%';
+-------------------------------+--------------------+
| Variable_name | Value |
+-------------------------------+--------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8mb4_0900_ai_ci |
| collation_server | utf8mb4_general_ci |
| default_collation_for_utf8mb4 | utf8mb4_general_ci |
+-------------------------------+--------------------+
4 rows in set (0.00 sec)

mysql> create table t4 (id int) DEFAULT CHARSET=utf8mb4 ;
Query OK, 0 rows affected (0.03 sec)

mysql> show create table t4;
+-------+--------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------+
| t4 | CREATE TABLE `t4` (
`id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci |
+-------+--------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
```
**Describe alternatives you've considered:**

**Teachability, Documentation, Adoption, Migration Strategy:**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.