Notepad:UTF8: Difference between revisions

From Amar
Jump to navigationJump to search
No edit summary
 
Line 18: Line 18:
  FROM INFORMATION_SCHEMA.COLUMNS  
  FROM INFORMATION_SCHEMA.COLUMNS  
  WHERE TABLE_SCHEMA='%%' AND COLLATION_NAME='latin1_swedish_ci';
  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}