When the collation_database is not utf8mb4_bin, for varchar fields created in a table, each field will explicitly specify its collation instead of implicitly inheriting it from the table.
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
When the collation_database is not utf8mb4_bin, for varchar fields created in a table, each field will explicitly specify its collation instead of implicitly inheriting it from the table. This makes the exported DDL statements appear very redundant and inconsistent with MySQL's default behavior.
Server version: 8.0.11-TiDB-v8.5.2 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like "%collation%";
+---------------------------------------+--------------------+
| Variable_name | Value |
+---------------------------------------+--------------------+
| collation_connection | utf8mb4_0900_ai_ci |
| collation_database | utf8mb4_bin |
| collation_server | utf8mb4_0900_ai_ci |
| default_collation_for_utf8mb4 | utf8mb4_0900_ai_ci |
| tidb_hash_exchange_with_new_collation | ON |
+---------------------------------------+--------------------+
5 rows in set (0.00 sec)
mysql> create database c0900ci;
Query OK, 0 rows affected (0.05 sec)
mysql> use c0900ci;
Database changed
mysql> create table t1(name varchar(10));
Query OK, 0 rows affected (0.06 sec)
mysql> show variables like "%collation%";
+---------------------------------------+--------------------+
| Variable_name | Value |
+---------------------------------------+--------------------+
| collation_connection | utf8mb4_0900_ai_ci |
| collation_database | utf8mb4_0900_ai_ci |
| collation_server | utf8mb4_0900_ai_ci |
| default_collation_for_utf8mb4 | utf8mb4_0900_ai_ci |
| tidb_hash_exchange_with_new_collation | ON |
+---------------------------------------+--------------------+
5 rows in set (0.00 sec)
mysql> show create table t1;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`name` varchar(10) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
### 2. What did you expect to see? (Required)
| t1 | CREATE TABLE `t1` (
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
### 3. What did you see instead (Required)
| t1 | CREATE TABLE `t1` (
`name` varchar(10) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
### 4. What is your TiDB version? (Required)
| Release Version: v8.5.2
Edition: Community
Git Commit Hash: f43a13324440f92209e2a9f04c0bbe9cf763978d
Git Branch: HEAD
UTC Build Time: 2025-05-29 03:30:55
GoVersion: go1.23.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------
Contributor guide
Assessment
This issue has not been assessed yet.