码迷,mamicode.com
首页 > 数据库 > 详细

mysql 字符集排查

时间:2018-11-13 20:17:51      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:gen   tables   end   排序规则   pre   form   order by   general   ati   

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' );

技术分享图片

表级别

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';

技术分享图片

字段级别

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;
  • 表默认排序规则。输出未显式列出表默认字符集,但排序规则名称以字符集名称开头。

技术分享图片

mysql 字符集排查

标签:gen   tables   end   排序规则   pre   form   order by   general   ati   

原文地址:https://www.cnblogs.com/gczheng/p/9953676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!