批量修改某个库下面,所有表字段的排序规则,执行下面的脚本
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'
);
将拿到的结果脚本再运行一次