Prepare a batch import keyword excel, which contains 2 keywords
1.pokemon
2.pokémon
Note: One of these two keywords is an ordinary e, and the other is a syllable é
Prepare database table sql script
-- 导入关键词表 CREATE TABLE `keyword_lexicon` ( `id` int(10) NOT NULL AUTO_INCREMENT, `keyword` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '搜索关键词', PRIMARY KEY ("id"), UNIQUE KEY "idx_keyword" ("keyword") USING BTREE COMMENT '关键词' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='导入关键词表';
Simply write an import interface, the code is not attached. It should be noted that the INSERT IGNORE INTO method is used to import sql. If the keyword already exists in the table, it will not be written to the table. (The keyword field is set as a unique index)
The import sql example is as follows
INSERT IGNORE INTO keyword_lexicon (`keyword`) VALUES ('pokemon'),('pokémon')
After adjusting the interface to complete the import, check the database table and find that there is only one piece of Pokemon data.
Looking at the table structure, we found that the sorting rule of the keyword field is
utf8mb4_general_ci
Then re-import. After viewing the results, you can find that both pieces of data have been inserted into the table, and the problem is solved.
##Summary
utf8mb4_bin is case-sensitive, and also distinguishes characters such as e and éThe above is the detailed content of Mysql inserts pinyin characters through INSERT IGNORE INTO. How to solve the problem?. For more information, please follow other related articles on the PHP Chinese website!