How do I see what character set a MySQL database / table / column is?

前端 未结 15 1435
失恋的感觉
失恋的感觉 2020-11-22 06:33

What is the (default) charset for:

  • MySQL database

  • MySQL table

  • MySQL column

15条回答
  •  北海茫月
    2020-11-22 06:48

    Here's how I'd do it -

    For Schemas (or Databases - they are synonyms):

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

    For Tables:

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

    For Columns:

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

提交回复
热议问题