什么是(默认的)字符集:

MySQL数据库 MySQL表 MySQL列


当前回答

正如前面所写的,SHOW FULL COLUMNS应该是获取列信息的首选方法。 缺少的是在不直接到达元数据表的情况下获取字符集的方法:

SHOW FULL COLUMNS FROM my_table WHERE Field = 'my_field'
SHOW COLLATION WHERE Collation = 'collation_you_got'

其他回答

我总是看SHOW CREATE TABLE mydatabase。mytable。

对于数据库,似乎需要查看SELECT DEFAULT_CHARACTER_SET_NAME FROM information_schema.SCHEMATA。

显示像'character_set_%'或'collation%'这样的变量

要查看数据库的默认排序规则:

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

要查看表格的排序:

SHOW TABLE STATUS where name like 'table_name';

要查看列的排序规则:

SHOW FULL COLUMNS FROM table_name;

查看表的默认字符集

SHOW CREATE TABLE table_name;
SELECT TABLE_SCHEMA,
       TABLE_NAME,
       CCSA.CHARACTER_SET_NAME AS DEFAULT_CHAR_SET,
       COLUMN_NAME,
       COLUMN_TYPE,
       C.CHARACTER_SET_NAME
  FROM information_schema.TABLES AS T
  JOIN information_schema.COLUMNS AS C USING (TABLE_SCHEMA, TABLE_NAME)
  JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY AS CCSA
       ON (T.TABLE_COLLATION = CCSA.COLLATION_NAME)
 WHERE TABLE_SCHEMA=SCHEMA()
   AND C.DATA_TYPE IN ('enum', 'varchar', 'char', 'text', 'mediumtext', 'longtext')
 ORDER BY TABLE_SCHEMA,
          TABLE_NAME,
          COLUMN_NAME
;

数据库:

只需使用这些命令:

USE db_name;
SELECT @@character_set_database;
-- or:
-- SELECT @@collation_database;