In MySQL, collation can be applied at many levels. It can be applied at the server level, the connection level, the database level, the table level, and even at the column level. You can also specify a collation in your queries that will override any collation that has been applied at the database, table, or column levels.
Here’s how to find out what collation is being applied at each of these levels.
Shortcut for Connection, Server, and Database Collation
The quickest way to get collation information for the connection, server, and database is to use the following statement. This statement returns all system variables starting with collation
:
SHOW VARIABLES LIKE 'collation%';
This returns the collation for the server, connection, and database. Like this:
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_0900_ai_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8mb4_0900_ai_ci |
+----------------------+--------------------+
You can also return each of these system variables separately if required. See below for instructions on how to do that.
Continue reading →