MySQL 5.7.6开始,MySQL内置了ngram全文解析器,用来支持中、日、韩文的分词
启动方法
配置mysql的ngram,打开mysql server的配置文件,编辑在[mysqld]下面加入这样的配置
代码语言:javascript复制# vim /etc/my.cnf
[mysqld]
ngram_token_size=2
查看是否开启
代码语言:javascript复制mysql> show variables like 'ngram_token_size%';
------------------ -------
| Variable_name | Value |
------------------ -------
| ngram_token_size | 1 |
------------------ -------
演示数据表
代码语言:javascript复制CREATE TABLE `t_testfulltext` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(128) DEFAULT NULL,
`data` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `ft_index` (`name`) /*!50100 WITH PARSER `ngram` */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
执行语句
代码语言:javascript复制SELECT * FROM t_testfulltext WHERE MATCH (name) AGAINST ('今天');
参考:https://cloud.tencent.com/developer/article/1634247?areaSource=&traceId=