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
Release: 2025-01-20 14:09:39
Original
242 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template