mysql - 如何更改 MySQL 中每个表中每个字段的冲突?

标签 mysql utf-8 character-encoding collision alter-table

我有 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/

相关文章:

LInux shell : conditional conversion of character encoding, 多个文本文件

php - 避免mysql一般错误: 1366 Incorrect string value

mysql - 分组后的随机数据

mysql - 如何从 mysqldump 获得与 mysqladmin/backup 完全相同的输出

mysql - 在 MySQL 中存储 UTF8 数据

JavaScript 编码和解码错误

mysql - 传递 jdbc 数据源与传递 Connection 对象 - 从 servlet 到 java 类

c# - 如何从 MS Access 转换到 MySQL?

encoding - 上传亚马逊库存 UTF 8 编码

java - UTF-8——ISO 8859-1映射工具