表字符集修改
SELECT
CONCAT(
'ALTER TABLE ',
TABLE_NAME,
' CONVERT TO CHARACTER SET utf8mb4;'
)
FROM
information_schema. TABLES
WHERE
TABLE_SCHEMA = 'dataBaseName';
表欄位字符集修改
SELECT
CONCAT(
'ALTER TABLE `',
TABLE_NAME,
'` MODIFY `',
COLUMN_NAME,
'` ',
DATA_TYPE,
'(',
CHARACTER_MAXIMUM_LENGTH,
')',
' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci',
if(COLUMN_DEFAULT is null ,'',concat(' default \'',COLUMN_DEFAULT,'\'')),
(
CASE
WHEN IS_NULLABLE = 'NO' THEN
' NOT NULL'
ELSE
''
END
),
';'
)
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'table_name'
AND (DATA_TYPE = 'varchar' OR DATA_TYPE = 'char')
and TABLE_NAME not in ('flyway_schema_history','undo_log');