Skip to content

Instantly share code, notes, and snippets.

@calexandrepcjr
Last active September 9, 2019 14:27
Show Gist options
  • Save calexandrepcjr/cfa99628a230f62b24704fabdc152092 to your computer and use it in GitHub Desktop.
Save calexandrepcjr/cfa99628a230f62b24704fabdc152092 to your computer and use it in GitHub Desktop.
This routine helps when someone needs to review the entire database charset/collation at once. You can run this SP and store in a CSV to help analysis or just manipulate the result inside the DB.
/*
TO MYSQL
List your entire schema + tables + columns charset and collations to overall review
WHAT IT DOES:
- The stored procedure goes into MySQL's information_schema table
and retrieves the overall info about your database;
HOW TO USE:
- Enter inside your schema with USE **YOUR_SCHEMA_NAME**;
- Run below code;
*/
DROP PROCEDURE IF EXISTS list_charset_and_collations;
CREATE PROCEDURE list_charset_and_collations()
BEGIN
SELECT (SELECT DATABASE()) as name, default_character_set_name as charset, default_collation_name as collation
FROM information_schema.SCHEMATA
WHERE schema_name = (SELECT DATABASE())
UNION
SELECT CONCAT('table: ', table_name) as name,
CCSA.character_set_name AS charset,
T.table_collation as collation
FROM information_schema.`TABLES` T
INNER JOIN information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA ON (CCSA.collation_name = T.table_collation)
WHERE T.table_schema = (SELECT DATABASE())
UNION
SELECT CONCAT('column: ', table_name, '.', column_name) as name,
character_set_name as charset,
collation_name as collation
FROM information_schema.`COLUMNS`
WHERE column_name = "description";
END;
-- HOW TO CALL
CALL list_charset_and_collations;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment