Notepad:UTF8: Difference between revisions
From Amar
Jump to navigationJump to search
Created page with "[https://dev.mysql.com/doc/refman/5.5/en/charset-applications.html Configuring the Character Set and Collation for Applications] CREATE DATABASE <DB> DEFAULT CHARACTER SET..." |
No edit summary |
||
Line 1: | Line 1: | ||
= Create a database with UTF-8 = | |||
[https://dev.mysql.com/doc/refman/5.5/en/charset-applications.html Configuring the Character Set and Collation for Applications] | [https://dev.mysql.com/doc/refman/5.5/en/charset-applications.html Configuring the Character Set and Collation for Applications] | ||
Line 6: | Line 7: | ||
use <DB>; | use <DB>; | ||
= Move a table to UTF-8 = | |||
SELECT DISTINCT CONCAT('ALTER TABLE ',TABLE_NAME,' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') | |||
FROM INFORMATION_SCHEMA.COLUMNS | |||
WHERE TABLE_SCHEMA='%%' AND COLLATION_NAME='latin1_swedish_ci'; | |||
= Move individual fields to UTF-8 = | |||
SELECT DISTINCT CONCAT('ALTER TABLE ',TABLE_NAME,' MODIFY ',COLUMN_NAME,' ',COLUMN_TYPE, | |||
' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') | |||
FROM INFORMATION_SCHEMA.COLUMNS | |||
WHERE TABLE_SCHEMA='%%' AND COLLATION_NAME='latin1_swedish_ci'; |
Revision as of 21:35, 19 November 2018
Create a database with UTF-8
Configuring the Character Set and Collation for Applications
CREATE DATABASE <DB> DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
use <DB>;
Move a table to UTF-8
SELECT DISTINCT CONCAT('ALTER TABLE ',TABLE_NAME,' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='%%' AND COLLATION_NAME='latin1_swedish_ci';
Move individual fields to UTF-8
SELECT DISTINCT CONCAT('ALTER TABLE ',TABLE_NAME,' MODIFY ',COLUMN_NAME,' ',COLUMN_TYPE, ' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='%%' AND COLLATION_NAME='latin1_swedish_ci';