Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joostvanveen/682412e1ff3e73e5209b823642fba02d to your computer and use it in GitHub Desktop.
Save joostvanveen/682412e1ff3e73e5209b823642fba02d to your computer and use it in GitHub Desktop.
Alter the charset and collation to UTF8 for a database and a table. Also inspects the default charset and collation for the entire database.
-- Inspect the default charset and collation for your database
SELECT default_character_set_name FROM information_schema.schemata WHERE schema_name = 'MYDATABASE_NAME';
-- Alter the default charset and collation for your database
-- CAREFUL: when you change the charset for your database, make sure the data in your tables matches that character set.
-- If it is not, follow these steps: http://www.alphadevx.com/a/420-Converting-a-MySQL-database-from-latin1-to-utf8
ALTER DATABASE MYDATABASE_NAME CHARACTER SET utf8 COLLATE utf8_general_ci;
-- Alter the default charset and collation for your database
ALTER TABLE MYTABLE_NAME CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment