如何将整个 MySQL 数据库字符集和排序规则转换为 UTF-8?

2021-11-20 00:00:00 character-encoding mysql

如何将整个 MySQL 数据库字符集转换为 UTF-8 并将排序规则转换为 UTF-8?

How can I convert entire MySQL database character-set to UTF-8 and collation to UTF-8?

推荐答案

使用ALTER DATABASEALTER TABLE 命令.

ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

或者,如果您仍在使用不支持 4 字节 UTF-8 的 MySQL 5.5.2 或更低版本,请使用 utf8 而不是 utf8mb4:

Or if you're still on MySQL 5.5.2 or older which didn't support 4-byte UTF-8, use utf8 instead of utf8mb4:

ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

相关文章