要讓專案可以儲存特殊字元(例如: 🎂 等 emoji )有以下的需求:
步驟:
進入 mysql 的 container
進入 mysql 指令 (mysql -u [專案資料庫的使用者] -p"[專案的使用者密碼]")
指定目標專案的資料庫 (use [專案資料庫])
執行
SELECT CONCAT('ALTER TABLE ', tbl.TABLE_SCHEMA, '.', tbl.TABLE_NAME, ' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;') AS ExecuteTheString FROM information_schema.TABLES tbl WHERE tbl.TABLE_SCHEMA = 'nuwa_homepage';
將結果複製至編輯器 (Notepad++ 即可)
以空字串取代 |
複製大概 50-80 行的合法指令,一部份一部份慢慢的在 mysql 的指令中執行
完成後就已經更改成功,可以隨意挑選一個 table 觀看 schema,應改 charset 為 utf8mb4 collate 為 utf8mb4_unicode_ci。 (show create table [隨意 Table]),結果應該如下:
+-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| template_editor_version | CREATE TABLE `template_editor_version` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dirName` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`fileName` varchar(256) COLLATE utf8mb4_unicode_ci NOT NULL,
`number` int(10) unsigned NOT NULL,
`checksum` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`conflict` tinyint(1) NOT NULL,
`nextVersion_id` int(11) DEFAULT NULL,
`preVersion_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `template_editor_vers_nextVersion_id_9680228e_fk_template_` (`nextVersion_id`),
KEY `template_editor_vers_preVersion_id_1893052b_fk_template_` (`preVersion_id`),
CONSTRAINT `template_editor_vers_nextVersion_id_9680228e_fk_template_` FOREIGN KEY (`nextVersion_id`) REFERENCES `template_editor_version` (`id`),
CONSTRAINT `template_editor_vers_preVersion_id_1893052b_fk_template_` FOREIGN KEY (`preVersion_id`) REFERENCES `template_editor_version` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1161 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
+-------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
參考來源: https://pcwiki.pixnet.net/blog/post/105578519 https://stackoverflow.com/questions/10859966/how-to-convert-all-tables-in-database-to-one-collation http://georgepavlides.info/convert-all-tables-in-a-mysql-database-to-utf8_general_ci/