如何查看 MySQL 数据库/表/列是什么字符集?

什么是(默认)字符集:

What is the (default) charset for:

  • MySQL 数据库

  • MySQL database

MySQL 表

MySQL 列

推荐答案

这是我的做法 -

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

For Schemas (or Databases - they are synonyms):

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";

相关文章