Home >Database >Mysql Tutorial >How to Retrieve Character Set Information for MySQL Databases, Tables, and Columns?

How to Retrieve Character Set Information for MySQL Databases, Tables, and Columns?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-20 14:18:10313browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn