批量修改某个库下面,所有表字段的排序规则,执行下面的脚本
SELECT
CONCAT(
'ALTER TABLE `',table_name,'` MODIFY `',column_name,'` ',DATA_TYPE,'(',CHARACTER_MAXIMUM_LENGTH,') CHARACTER SET UTF8 COLLATE utf8_general_ci',(
CASE
WHEN IS_NULLABLE = 'NO' THEN
' NOT NULL'
ELSE
''
END
),';'
)
FROM
information_schema. COLUMNS
WHERE
TABLE_SCHEMA = 'schema_name'
AND DATA_TYPE = 'varchar'
AND (
CHARACTER_SET_NAME != 'utf8'
OR COLLATION_NAME != 'utf8_general_ci'
);
将拿到的结果脚本再运行一次
原文链接:https://www.f2er.com/note/422068.html