alter table xxx表 convert to character set utf8mb4 collate utf8mb4_unicode_ci;
select
concat(
'alter table `' ,table_name,
'` modify `' , column_name,
'` ' , column_type,
' character set utf8mb4 collate utf8mb4_unicode_ci;'
) as alter_sql
from
information_schema.`COLUMNS`
where
table_schema = 'xxx数据库名'
and table_name = 'xxxx数据库表名'
and data_type in ('varchar','char','text','tinytext','mediumtext','longtext');
如:
alter table `xxx表名` modify `xxx字段名` varchar(50) character set utfmb4 collate utf8mb4_unicode_ci;
....