【问题标题】:How do I change collision of every field in every table in MySQL?如何更改 MySQL 中每个表中每个字段的冲突?
【发布时间】:2011-12-21 01:05:44
【问题描述】:
我有 8 个表,其中的许多字段都是用拉丁字符集创建的。
我想将它们全部转换为 UTF-8。
对于数据库和表,我可以手动完成。
如何以编程方式处理字段?
【问题讨论】:
标签:
mysql
utf-8
character-encoding
collision
alter-table
【解决方案1】:
我想推荐information_schema.columns。
这是一个非常有用的视图。
获取不在 UTF-8 中的列的列表:-
select table_schema, table_name, column_name, character_set_name, collation_name
from information_schema.columns
where table_schema in ('YOUR_DB') and collation_name not like 'utf8%';
select table_schema, table_name, column_name, character_set_name, collation_name
from information_schema.columns
where table_schema in ('YOUR_DB') and character_set_name not like 'utf8%';
这个视图最好的地方...它还包括列的数据类型(请参阅文档中的 COLUMN_TYPE)、默认值(请参阅 COLUMN_DEFAULT)等...
有了所有这些信息,我认为很容易在编程语言上使用来构造相关的 SQL(并执行它)