MySql-修改表、字段、库的字符集

对表、字段、库的字符集的一些常规操作。

修改数据库字符集:

ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE …];

把表默认的字符集和所有字符列(CHAR,VARCHAR,TEXT)改为新的字符集:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET character_name [COLLATE …]
如:ALTER TABLE logtest CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

此处写utf8_general_ci有时候会报错,直接写utf8即可

alter table logtest convert to character set utf8;

只是修改表的默认字符集:

ALTER TABLE tbl_name DEFAULT CHARACTER SET character_name [COLLATE…];
如:ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

修改字段的字符集:

ALTER TABLE tbl_name CHANGE c_name c_name CHARACTER SET character_name [COLLATE …];
如:ALTER TABLE logtest CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci;

查看数据库编码:

SHOW CREATE DATABASE db_name;

查看表编码:

SHOW CREATE TABLE tbl_name;

查看字段编码:

SHOW FULL COLUMNS FROM tbl_name;

本文标题:MySql-修改表、字段、库的字符集

文章作者:郑上进

本文链接:http://blog.zjc123.cn/2019/04/13/MySql-ModifyCharacterSetsofTables-Fields-Libraries/

许可协议:转载请保留原文链接及作者姓名。

-------------本文结束感谢您的阅读-------------