mysql 中文全文索引

use test;
show variables like 'innodb_ft_min_token_size';
## innodb_ft_min_token_size    2

show variables like 'ft%';

## ft_min_word_len    1

REPAIR TABLE product;

show create table product;

CREATE TABLE `product` (
   `id` int(10) NOT NULL AUTO_INCREMENT,
   `title` varchar(200) NOT NULL DEFAULT '' COMMENT '商品名称',
   PRIMARY KEY (`id`),
   FULLTEXT KEY `full_title` (`title`) with parser ngram
 ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
 
 ## 注意这里一定要用到 with parser ngram
 alter table product add FULLTEXT KEY `full_title` (`title`) with parser ngram;
 
 
 insert into product(title)values('青岛啤酒'),('雪花啤酒'),('哈尔滨啤酒'),('牛栏山二锅头'),('红星二锅头'),('are you ok?'),('how are you'),('how do you do'),('what are you doing now?'),('hello');

select * from product;
select * from product where match(title) against('you' In natural language mode);
select * from product where match(title) against('哈尔滨');
select * from product where match(title) against('"青岛"' IN BOOLEAN MODE);


## 重建索引
REPAIR TABLE product QUICK;
ALTER TABLE product ENGINE=INNODB;
OPTIMIZE TABLE product;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值