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

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

What is the (default) charset for:

  • MySQL database

  • MySQL table

  • MySQL column

相关标签:
15条回答
  • 2020-11-22 06:54

    To see default collation of the database:

    USE db_name;
    SELECT @@character_set_database, @@collation_database;
    

    To see collation of the table:

    SHOW TABLE STATUS where name like 'table_name';
    

    To see collation of the columns:

    SHOW FULL COLUMNS FROM table_name;
    

    To see the default character set of a table

    SHOW CREATE TABLE table_name;
    
    0 讨论(0)
  • 2020-11-22 06:57

    For columns:

    SHOW FULL COLUMNS FROM table_name;
    
    0 讨论(0)
  • 2020-11-22 07:00

    show global variables where variable_name like 'character_set_%' or variable_name like 'collation%'

    0 讨论(0)
  • 2020-11-22 07:02

    As many wrote earlier, SHOW FULL COLUMNS should be the preferred method to get column information. What's missing is a way to get charset after that without reaching metadata tables directly:

    SHOW FULL COLUMNS FROM my_table WHERE Field = 'my_field'
    SHOW COLLATION WHERE Collation = 'collation_you_got'
    
    0 讨论(0)
  • 2020-11-22 07:03

    For database : USE db_name; SELECT @@character_set_database;

    0 讨论(0)
  • 2020-11-22 07:11

    For databases:

    SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
    

    Example output:

    mysql> SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
    +----------------------------+---------+--------------------+
    | database                   | charset | collation          |
    +----------------------------+---------+--------------------+
    | information_schema         | utf8    | utf8_general_ci    |
    | drupal_demo1               | utf8    | utf8_general_ci    |
    | drupal_demo2               | utf8    | utf8_general_ci    |
    | drupal_demo3               | utf8    | utf8_general_ci    |
    | drupal_demo4               | utf8    | utf8_general_ci    |
    | drupal_demo5               | latin1  | latin1_swedish_ci  |
    
    ...
    
    +----------------------------+---------+--------------------+
    55 rows in set (0.00 sec)
    
    mysql> 
    
    0 讨论(0)
提交回复
热议问题