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..." |
|||
(One intermediate revision by the same user not shown) | |||
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'; | |||
Then before executing: | |||
{code}SET FOREIGN_KEY_CHECKS=0;{/code} |
Latest revision as of 21:36, 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';
Then before executing:
{code}SET FOREIGN_KEY_CHECKS=0;{/code}