协慌网

登录 贡献 社区

如何查看 MySQL 数据库 / 表 / 列的字符集?

(默认)字符集是什么:

  • MySQL 数据库

  • MySQL 表

  • MySQL 专栏

答案

这是我的做法 -

对于模式(或数据库 - 它们是同义词):

SELECT default_character_set_name FROM information_schema.SCHEMATA 
WHERE schema_name = "schemaname";

对于表:

SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
       information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
  AND T.table_schema = "schemaname"
  AND T.table_name = "tablename";

对于列:

SELECT character_set_name FROM information_schema.`COLUMNS` 
WHERE table_schema = "schemaname"
  AND table_name = "tablename"
  AND column_name = "columnname";

对于

SHOW FULL COLUMNS FROM table_name;

对于数据库

USE your_database_name;
show variables like "character_set_database";
-- or:
-- show variables like "collation_database";

cf.此页。并查看 MySQL 手册