What is the (default) charset for:
MySQL database
MySQL table
MySQL column
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;
For columns:
SHOW FULL COLUMNS FROM table_name;
show global variables where variable_name like 'character_set_%' or variable_name like 'collation%'
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'
For database :
USE db_name; SELECT @@character_set_database;
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>