mysql 字符集排查

mysql 字符集排查

库级别

SELECT
    * 
FROM
    information_schema.schemata 
WHERE
    schema_name NOT IN ( 'information_schema', 'performance_schema', 'mysql', 'sys' ) 
    AND ( default_character_set_name <> 'utf8' OR default_collation_name <> 'utf8_general_ci' );

1166598-20181113180938233-2000044370.png

表级别

SELECT 
    TABLE_SCHEMA,
    TABLE_NAME,
    TABLE_TYPE,
    TABLE_ROWS,
    TABLE_COLLATION,
    CREATE_OPTIONS
FROM
    information_schema.TABLES
WHERE
    TABLE_TYPE = 'BASE TABLE'
        AND TABLE_SCHEMA NOT IN ('information_schema' , 'performance_schema', 'mysql', 'sys')
        AND TABLE_COLLATION <> 'utf8_general_ci';

1166598-20181113180950043-1627880469.png

字段级别

SELECT 
    TABLE_SCHEMA AS '库名',
    DEFAULT_CHARACTER_SET_NAME AS '库的字符集',
    DEFAULT_COLLATION_NAME AS '库的校对字符集',
    TABLE_NAME AS '表名',
    TABLE_COLLATION AS '表的校对规则',
    COLUMN_NAME AS '字段名',
    CHARACTER_SET_NAME AS '字段的字符集',
    COLLATION_NAME AS '字段的校对规则'
FROM
    (SELECT 
        C2.TABLE_SCHEMA,
            C2.TABLE_NAME,
            C2.CHARACTER_SET_NAME,
            T2.TABLE_COLLATION,
            C2.COLUMN_NAME,
            C2.COLLATION_NAME,
            S2.DEFAULT_CHARACTER_SET_NAME,
            S2.DEFAULT_COLLATION_NAME,
            CASE
                WHEN
                    S2.DEFAULT_CHARACTER_SET_NAME = 'utf8'
                        AND S2.DEFAULT_COLLATION_NAME = 'utf8_general_ci'
                        AND (C2.CHARACTER_SET_NAME = 'utf8'
                        OR C2.CHARACTER_SET_NAME IS NULL)
                        AND (C2.COLLATION_NAME = 'utf8_general_ci'
                        OR C2.COLLATION_NAME IS NULL)
                        AND T2.TABLE_COLLATION = 'utf8_general_ci'
                THEN
                    'true'
                ELSE 'false'
            END STATUS
    FROM
        information_schema.COLUMNS AS C2
    JOIN (SELECT 
        TABLE_SCHEMA,
            TABLE_NAME,
            TABLE_TYPE,
            TABLE_ROWS,
            TABLE_COLLATION,
            CREATE_OPTIONS
    FROM
        information_schema.TABLES
    WHERE
        TABLE_TYPE = 'BASE TABLE'
            AND TABLE_SCHEMA NOT IN ('information_schema' , 'sys', 'performance_schema', 'mysql')) T2 ON C2.TABLE_NAME = T2.TABLE_NAME
        AND C2.TABLE_SCHEMA = T2.TABLE_SCHEMA
    JOIN (SELECT 
        SCHEMA_NAME,
            DEFAULT_CHARACTER_SET_NAME,
            DEFAULT_COLLATION_NAME
    FROM
        information_schema.SCHEMATA) S2 ON T2.TABLE_SCHEMA = S2.SCHEMA_NAME) charset_status
WHERE
    STATUS = 'false'
ORDER BY TABLE_SCHEMA , TABLE_NAME;
  • 表默认排序规则。输出未显式列出表默认字符集,但排序规则名称以字符集名称开头。

1166598-20181113181003368-1419457481.png

转载于:https://www.cnblogs.com/gczheng/p/9953676.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值