012.mysql-mysql查询字段排序规则、数据库编码、表编码,修改排序规则

查询字段排序规则、数据库编码、表编码

 

SELECT 

TABLE_CATALOG, 

TABLE_SCHEMA, 

TABLE_NAME,

 COLUMN_NAME, 

COLLATION_NAME
FROM INFORMATION_SCHEMA.COLUMNS

 

 

 

 

表字段修复

#改变字段数据 字符集、排序规则
SELECT
    TABLE_SCHEMA '数据库',
    TABLE_NAME '',
    COLUMN_NAME '字段',
    CHARACTER_SET_NAME '原字符集',
    COLLATION_NAME '原排序规则',
    CONCAT( 'ALTER TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ' MODIFY COLUMN ', COLUMN_NAME, ' ', COLUMN_TYPE, ' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;' ) '修正SQL' 
FROM
    information_schema.`COLUMNS` 
WHERE
    TABLE_NAME = 'ud_dm_org_cas_stat'  and COLLATION_NAME RLIKE 'utf8_general_ci';

表修复

#改变表
SELECT
    TABLE_SCHEMA '数据库',
    TABLE_NAME '',
    TABLE_COLLATION '原排序规则',
    CONCAT( 'ALTER TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ' COLLATE=utf8mb4_general_ci;' ) '修正SQL' 
FROM
    information_schema.`TABLES` 
WHERE
    TABLE_NAME = 'ud_yqyc_ryb' 

数据库修复

#修改数据库
SELECT
    SCHEMA_NAME '数据库',
    DEFAULT_CHARACTER_SET_NAME '原字符集',
    DEFAULT_COLLATION_NAME '原排序规则',
    CONCAT( 'ALTER DATABASE ', SCHEMA_NAME, ' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;' ) '修正SQL' 
FROM
    information_schema.`SCHEMATA` 
WHERE
    DEFAULT_CHARACTER_SET_NAME RLIKE 'utf8';
 ;
 
 ALTER DATABASE 库名 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

 

posted @ 2020-09-18 15:14  star521  阅读(694)  评论(0编辑  收藏  举报