使用如下 SQL 语句即可更新一张表的字符集 (character set) 和排序规则 (collation):
1 2
| ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
|
然后可以使用如下 SQL 查询表和列的字符集和排序规则是否修改成功:
1 2 3 4 5 6 7 8 9
| SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `TABLE_COLLATION` FROM `information_schema`.`TABLES` WHERE `TABLE_NAME` = 'table_name';
SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`, `COLLATION_NAME` FROM `information_schema`.`COLUMNS` WHERE `TABLE_NAME` = 'table_name';
|