Home >Database >Mysql Tutorial >How to Retrieve Character Set Information for MySQL Databases, Tables, and Columns?
MySQL Character Set Information: A Comprehensive Guide
This guide demonstrates how to retrieve character set information for different MySQL database objects.
Database-Level Character Set
To find the default character set of a MySQL database, use this query:
<code class="language-sql">SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = 'your_database_name';</code>
Table-Level Character Set
The following query retrieves the character set for a specific table:
<code class="language-sql">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 = 'your_database_name' AND T.table_name = 'your_table_name';</code>
Column-Level Character Set
To obtain the character set of a particular column within a table, execute this query:
<code class="language-sql">SELECT character_set_name FROM information_schema.COLUMNS WHERE table_schema = 'your_database_name' AND table_name = 'your_table_name' AND column_name = 'your_column_name';</code>
Remember to replace placeholders like your_database_name
, your_table_name
, and your_column_name
with your actual database, table, and column names.
The above is the detailed content of How to Retrieve Character Set Information for MySQL Databases, Tables, and Columns?. For more information, please follow other related articles on the PHP Chinese website!