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

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

What is the (default) charset for:

  • MySQL database

  • MySQL table

  • MySQL column

相关标签:
15条回答
  • 2020-11-22 07:12

    For databases:

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

    Cf. this page. And check out the MySQL manual

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

    For all the databases you have on the server:

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

    Output:

    +----------------------------+---------+--------------------+
    | database                   | charset | collation          |
    +----------------------------+---------+--------------------+
    | information_schema         | utf8    | utf8_general_ci    |
    | my_database                | latin1  | latin1_swedish_ci  |
    ...
    +----------------------------+---------+--------------------+
    

    For a single Database:

    mysql> USE my_database;
    mysql> show variables like "character_set_database";
    

    Output:

        +----------------------------+---------+
        | Variable_name              |  Value  |
        +----------------------------+---------+
        | character_set_database     |  latin1 | 
        +----------------------------+---------+
    

    Getting the collation for Tables:

    mysql> USE my_database;
    mysql> SHOW TABLE STATUS WHERE NAME LIKE 'my_tablename';
    

    OR - will output the complete SQL for create table:

    mysql> show create table my_tablename


    Getting the collation of columns:

    mysql> SHOW FULL COLUMNS FROM my_tablename;
    

    output:

    +---------+--------------+--------------------+ ....
    | field   | type         | collation          |
    +---------+--------------+--------------------+ ....
    | id      | int(10)      | (NULL)             |
    | key     | varchar(255) | latin1_swedish_ci  |
    | value   | varchar(255) | latin1_swedish_ci  |
    +---------+--------------+--------------------+ ....
    
    0 讨论(0)
  • 2020-11-22 07:12

    I always just look at SHOW CREATE TABLE mydatabase.mytable.

    For the database, it appears you need to look at SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA.

    0 讨论(0)
提交回复
热议问题