Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

What is the (default) charset for:

  • MySQL database

  • MySQL table

  • MySQL column

like image 993
Amandasaurus Avatar asked Jun 26 '09 15:06

Amandasaurus


People also ask

How do I find the charset of a table in MySQL?

To see the default character set and collation for a given database, use these statements: USE db_name; SELECT @@character_set_database, @@collation_database; Alternatively, to display the values without changing the default database: SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.

How do I find the character set in SQL?

To display the available character sets, use the INFORMATION_SCHEMA CHARACTER_SETS table or the SHOW CHARACTER SET statement.

How do you determine the datatype of a column in a database?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.


1 Answers

Here's how I'd do it -

For Schemas (or Databases - they are synonyms):

SELECT default_character_set_name FROM information_schema.SCHEMATA  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`  WHERE table_schema = "schemaname"   AND table_name = "tablename"   AND column_name = "columnname"; 
like image 65
Zenshai Avatar answered Nov 23 '22 10:11

Zenshai