本文主要介绍数据库-Mysql的全文检索
什么是全文检索
我理解就是根据关键字查出所有相关的信息;比如一个电商网站,输入一件商品名称,会搜出来相应的商品信息;或许一些站内搜索,会全网站搜索相关资源。
当然,这里假定为一个web管理系统,Mysql数据库,用户输入商品名称,要从数据库中检索出对应的商品
全文检索手段
1.Apache 的Lucene,还有基于它的solr下载2.sphinx
3.Mysql自带的
4.Mysql插件oneSql
这里主要介绍下第4种Mysql插件oneSql,因为它实现了中文分词,而正是需要它!
oneSql
亲测可用(非生产,稳定性及性能不在讨论范围),不过有些遗憾的是,它是收费的。所以下载的版本如果有问题及需要支持就要掏钱了,也处顺便给大神打个广告平民软件
测试环境
1.centos7,运行于虚拟机Vmware12
2.Mysql5.7点击打开链接
3.oneSql插件点击打开链接
安装centos
这里面可以选择是否安装界面,默认不安装

选择开启网络

设置密码

安装mysql
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
把下载的文件用FTP传到centos虚拟机
解压tar包

之后进行安装:sudo yum install mysql-community-{server,client,common,libs}-*

这个时候可能会报冲突
主要是这个,
尝试把它去掉
再重试,

安装完成
查看安装的rpm包

启动mysql:sudo service mysqld start

查看初始密码

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY'Tangwei!123';

如果要远程连接,关闭一下防火墙
CentOS7.0默认使用的是firewall作为防火墙
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
允许Mysql远程连接
# mysql -u root -proot
mysql>GRANT ALL PRIVILEGES ON*.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
操作完后切记执行以下命令刷新权限
FLUSHPRIVILEGES

连接成功!
安装onesql插件
参考:http://blog.csdn.net/rookie_ceo/article/details/48104083
http://man.linuxde.net/rpm
上传插件

安装一下

查看一下安装位置

停止mysql先

然后用onesql启动

查看一下分词插件

修改一下mysql参数
参考:http://www.onexsoft.com/zh/mysql-fulltext-search-with-friso.html
http://www.onexsoft.com/zh/onesql-friso-fulltext-plugin.html
https://www.cnblogs.com/devcjq/articles/6409470.html
设置全局变量方法1(不推荐): 修改参数文件, 然后重启mysqld
# vi /etc/my.cnf
[mysqld]
wait_timeout=10
# service mysqld restart
不过这个方法太生硬了, 线上服务重启无论如何都应该尽可能避免.

然后重启mysql

然后测试分词
show variables like'%min_word_len';
show variables like'%min_token_size';
show variables like 'friso%';
SELECT * FROM articles
WHERE MATCH(title,body) AGAINST('数据库')
DROP TABLE t_fulltext;
SELECT * FROM t_fulltext;
create table t_fulltext (
id int not null primary key,
doc varchar(100)) charset utf8;
create fulltext indexidx_t_fulltext
on t_fulltext(doc)
with parser friso;
insert into t_fulltext values (1,'中文Search');
select * from t_fulltext
where match(doc) against ('中文');

成功了
停止onesql
