#在ALTER语句修改数据库属性时会限制某些操作尤其是写操作,因此此方法不建议在生产环境使用.
#生产环境下可以使用MySQL在线修改功能(好像是5.6以上),还可以使用工具或者主从切换
#需要把生成的语句复制并执行
#生成修改指定数据库中全部表的字符集的语句
select CONCAT(‘ALTER TABLE ‘,table_name,’ DEFAULT CHARACTER SET 字符集 COLLATE 排序规则;’)
from information_schema.tables where table_schema=‘数据库’;
#查看指定数据库中表的全部属性按字符集排序
select * from information_schema.tables where table_schema=‘数据库’ order by CHARACTER_SET_NAME desc;
#生成修改指定数据库全部字段字符集的语句(这里只修改原字符集是utf8的)
select
CONCAT(‘ALTER TABLE ',table_name,'
CHANGE ‘,column_name,’ ‘,column_name,’ ‘,data_type,’(’,character_maximum_length,’)’
,’ CHARACTER SET 字符集 COLLATE 排序规则;’)
from information_schema.columns where table_schema= ‘数据库’ and CHARACTER_SET_NAME=‘utf8’;
#查看修改后的指定库的全部字段的属性按字符集排序
select * from information_schema.columns where table_schema=‘数据库’ order by CHARACTER_SET_NAME desc;