After setting the collation to utf8mb4_general_ci in TiDB 6.5, if the create table statement specifies default charset=utf8 but does not specify a collation, what will be the collation of the table?

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

Original topic: TiDB6.5 设置排序规则为utf8mb4_general_ci之后,如果create table语句中指定了default charset=utf8 但是没有指定排序规则 那么该表的排序规则是啥

| username: TiDBer_20QjYTLl

After setting the collation to utf8mb4_general_ci in TiDB 6.5, if the create table statement specifies default charset=utf8 but does not specify a collation, what will be the collation of the table? Will it be utf8_bin or utf8mb4_general_ci?

| username: caiyfc | Original post link

Character Sets and Collations | PingCAP Documentation Center

| username: TiDBer_20QjYTLl | Original post link

I am not asking about the priority order.

| username: caiyfc | Original post link

So I changed it, haha. I misread it at first.

| username: Miracle | Original post link

If no collation is specified but a character set is specified, the default collation will use the default collation of the specified character set.

| username: 小龙虾爱大龙虾 | Original post link

The previous statement is correct. It is recommended to specify the character set and collation when creating the database, and not to specify these two clauses when creating the table.

| username: Kongdom | Original post link

I think it’s utf8_bin, but I’m too lazy to verify it :yum:

| username: 小于同学 | Original post link

utf8_bin

| username: DBAER | Original post link

Testing :slight_smile:

| username: dba远航 | Original post link

Collation is utf8mb4_general_ci.

| username: TiDBer_RjzUpGDL | Original post link

utf8_bin

| username: 不想干活 | Original post link

utf8_bin

| username: zhaokede | Original post link

There is a default character set corresponding to the default collation, check the documentation.

| username: vincentLi | Original post link

Seeing is believing. You can do an experiment: after creating the table, use the show create table statement to see what the table creation statement looks like. I guess utf8mb4_general_ci is more likely.

| username: mono | Original post link

Guessed wrong. :joy: The default sorting for utf8 encoding is utf8_bin. If not specified, this is the default.

| username: zhang_2023 | Original post link

Will use matching character sets.

| username: redgame | Original post link

The default character set is utf8_bin.

| username: vincentLi | Original post link

You’re right. I misunderstood the question. I thought default_charset was utf8bm4.

| username: TiDBer_aaO4sU46 | Original post link

utf8_bin

| username: 这里介绍不了我 | Original post link

utf8_bin matches the character set.