Home >Database >Mysql Tutorial >How Can I Determine MySQL Character Sets at the Database, Table, and Column Levels?

How Can I Determine MySQL Character Sets at the Database, Table, and Column Levels?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-20 14:09:39243browse

How Can I Determine MySQL Character Sets at the Database, Table, and Column Levels?

How to determine the character set of MySQL database, table and column

This article introduces methods for determining different levels of character sets in MySQL databases, including:

Database character set

To retrieve the default character set for a specific database, use the following query:

<code class="language-sql">SELECT default_character_set_name FROM information_schema.SCHEMATA 
WHERE schema_name = "mydatabasename";</code>

Table character set

To determine the character set of a table, execute the following query:

<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 = "mydatabasename"
  AND T.table_name = "tablename";</code>

Column character set

Finally, to retrieve the character set of a specific column, use the following query:

<code class="language-sql">SELECT character_set_name FROM information_schema.`COLUMNS` 
WHERE table_schema = "mydatabasename"
  AND table_name = "tablename"
  AND column_name = "columnname";</code>

The above is the detailed content of How Can I Determine MySQL Character Sets at the Database, Table, and Column Levels?. 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