生成变更语句
SELECT
CONCAT(
'ALTER TABLE ', TABLE_NAME,
' MODIFY ', COLUMN_NAME,
' ', COLUMN_TYPE, ' ',
' CHARACTER SET utf8 COLLATE utf8_general_ci ',
CASE
WHEN IS_NULLABLE = 'YES' THEN ' NULL DEFAULT NULL '
WHEN IS_NULLABLE = 'NO' AND ISNULL(COLUMN_DEFAULT) THEN 'NOT NULL '
ELSE CONCAT("NOT NULL DEFAULT '",COLUMN_DEFAULT,"'")
END,
"COMMENT '",
COLUMN_COMMENT,
"';"
) AS alter_statement
FROM
INFORMATION_SCHEMA.`COLUMNS`
WHERE
TABLE_SCHEMA = '你的数据库名称'
AND
CHARACTER_SET_NAME = 'gbk'
AND
TABLE_NAME IN (
SELECT
TABLE_NAME
FROM
information_schema.`TABLES`
WHERE
TABLE_SCHEMA = '你的数据库名称'
AND
TABLE_TYPE = 'BASE TABLE'
);
如下图所示,修改语句中的你的数据库名称
,放到查询页面,运行后自动生成变更语句!
运行查询结果
将上一步骤生成的变更语句复制到新的查询页面运行,即可完成所有varchar
字符集的变更。
注意
:一定要在修改字符集
数据库下运行,否则可能会报如下错误:
Err] 1044 - Access denied for user 'rdis'@'%' to database 'information_schema'