1.所有字段字符集修改-执行如下sql,执行生成sql:

select
    concat(
        'alter table dbName.',
        table_name,
        ' modify ',
        column_name,
        ' ',
        data_type,
        '(',
        character_maximum_length,
        ') character set utf8mb4  collate utf8mb4_unicode_ci',
        (
            case
            when is_nullable = 'no' then
                ' not null default \'\''
            else
                ''
            end
        ),
        ';'
    )
from
    information_schema.columns
where
    table_schema = 'dbName'
and (data_type = 'varchar' or data_type = 'char')

 2.所有表字符集修改-执行如下sql,执行生成sql:

select
    concat(
        'alter table dbName.',
        table_name,
        ' CHARACTER SET = utf8mb4, COLLATE = utf8mb4_unicode_ci;'
    )
from
    information_schema.tables
where
    table_schema = 'dbName';

 

相关文章:

  • 2022-02-09
  • 2022-01-29
  • 2022-02-13
  • 2021-08-30
  • 2022-01-05
  • 2021-12-08
猜你喜欢
  • 2022-12-23
  • 2022-02-02
  • 2021-09-20
  • 2022-01-05
相关资源
相似解决方案