views:

592

answers:

5

How do I see what the character set that a MySQL database, table and column are in? Is there something like

SHOW CHARACTER SET FOR mydatabase;

and

SHOW CHARACTER SET FOR mydatabase.mytable;

and

SHOW CHARACTER SET FOR mydatabase.mytable.mycolumn;
A: 

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.

chaos
in mysql databases can have default character sets
James
Hm, so they do.
chaos
+1  A: 

SHOW TABLE STATUS will list all the tables, and the collation column contains details about the character set it uses, which might be of some help?

Vex
A: 
show create table X

should have some useful info

James
+2  A: 
USE your_database_of_interest;

and type,

show variables like "character_set_database";
show variables like "collation_database";

Cf. this page. And check out the MySQL manual

sheepsimulator
+3  A: 

Here's how I'd do it -

For Schemas:

SELECT default_character_set_name FROM information_schema.SCHEMATA S
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` C
WHERE schema_name = "schemaname"
  AND table_name = "tablename"
  AND column_name = "columnname";
Zenshai
Should be noted that information_schema is only in MySQL 5 onwards I believe.
Vex