Sunday, January 1, 2017

Convert Non-UTF8 tables to UTF8 in sql database

-- convert old text columns to blob,
ALTER TABLE my_table CHANGE my_column_name my_column_name BLOB;
-- then update table character set
ALTER ignore TABLE my_table CONVERT TO CHARACTER SET utf8;
-- then convert the text columns back to text type
ALTER TABLE my_table CHANGE my_column_name my_column_name TEXT;

-- If your old scripts break, try explicitly setting the names to UTF8 before making sql queries
SET NAMES utf8;
SELECT my_column_name FROM my_table limit 10;

No comments:

Post a Comment