Allin Program

一次性查出数据库中表和字段的字符集与排序规则

论如何全面地查看MySQL中表和字段的字符集与排序规则。

SQL

SELECT 
    TABLE_NAME,
    COLUMN_NAME,
    CHARACTER_SET_NAME AS CHARACTER_SET,
    COLLATION_NAME AS COLLATE
FROM 
    information_schema.COLUMNS
WHERE 
    TABLE_SCHEMA = 'your_database_name';

Result Example

TABLE_NAME COLUMN_NAME CHARACTER_SET COLLATE
users username utf8mb4 utf8mb4_unicode_ci
users password utf8mb4 utf8mb4_general_ci
orders order_code utf8mb4 utf8mb4_unicode_ci