Notepad:UTF8

From Amar
Revision as of 21:36, 19 November 2018 by Lax (talk | contribs) (→‎Move individual fields to UTF-8)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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}