Notepad:UTF8

From Amar
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}