mysql检查表的排序规则


106

如何查看表格的排序规则?IE浏览器,我想看:

+-----------------------------+
|  table  |     collation     |
|-----------------------------|
| t_name  |  latin_general_ci |
+-----------------------------+

Answers:




14

您还可以查询INFORMATION_SCHEMA.TABLES并获取特定表的排序规则:

SELECT TABLE_SCHEMA
    , TABLE_NAME
    , TABLE_COLLATION 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 't_name';

SHOW TABLE STATUS包含许多不相关信息的输出相比,它提供了更具可读性的输出。


请注意,排序规则也可以应用于列(排序规则可能与表本身不同)。要获取特定表的列排序规则,可以查询INFORMATION_SCHEMA.COLUMNS

SELECT TABLE_SCHEMA 
    , TABLE_NAME 
    , COLUMN_NAME 
    , COLLATION_NAME 
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 't_name';

2
适用于mariaDB 10.4
Tarator

8

使用此查询:

SHOW CREATE TABLE tablename

您将获得与表有关的所有信息。


3
SHOW CREATE TABLE将不显示排序规则。您必须使用如上所述的SHOW TABLE STATUS。
KateYoak '16

1
在mysql 5.5.52中对我有效。...) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1我的猜测是,如果它在更高版本的mysql / mariadb中设置为数据库的默认排序规则,则可能不会显示排序规则。
DeveloperChris

1
@DeveloperChris您显示的是字符集,而不是排序规则。两个表可能具有相同的字符集utf8,但归类utf8_general_ci与却不同utf8_unicode_ci。这可能会导致错误消息,例如HY000, 1267, Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='...,这是使我进入此页面的消息。
Dewi Morgan

0

该命令描述

mysql> use <database name> 

mysql> show table status like '<table name>';

+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+---------------------+------------+--------------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time         | Check_time | Collation          | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+---------------------+------------+--------------------+----------+----------------+---------+
| test | InnoDB |      11 | Dynamic    |   52 |            315 |       16384 |               0 |            0 |         0 |             59 | NULL        | 2020-04-16 23:00:00 | NULL       | utf8mb4_unicode_ci |     NULL |                |         |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+---------------------+------------+--------------------+----------+----------------+---------+
1 row in set (0.01 sec)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.