我有 8 个表,其中有许多字段,全部都是使用拉丁字符集创建的。
我想将它们全部转换为 UTF-8。
对于数据库和表,我可以手动完成。
如何以编程方式对字段执行此操作?
最佳答案
我想推荐information_schema.columns .
这是一个非常有用的 View 。
获取非 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%';
这个 View 最好的地方...它还包括列的数据类型(请参阅文档中的COLUMN_TYPE)、默认值(请参阅COLUMN_DEFAULT)等...
有了所有这些信息,我认为使用编程语言来构建相关的 SQL(并执行它)非常容易
关于mysql - 如何更改 MySQL 中每个表中每个字段的冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583970/