前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu系统,搭建mysql+sphinx环建

Ubuntu系统,搭建mysql+sphinx环建

作者头像
王亚昌
发布2018-08-03 15:57:38
1.6K0
发布2018-08-03 15:57:38
举报
文章被收录于专栏:王亚昌的专栏王亚昌的专栏

本文介绍下如何在ubuntu系统中,利用apt工具,搭建mysql+sphinx的全文检索环境。

一 安装mysql

1 更新源列表 打开"终端窗口",输入"sudo apt-get update"-->回车-->"输入root用户的密码"-->回车,就可以了。如果不运行该命令,直接安装mysql,会出现"有几个软件包无法下载,您可以运行apt-get update------"的错误提示,导致无法安装。 2 安装mysql 打开"终端窗口",输入"sudo apt-get install mysql-server mysql-client"-->回车-->输入"y"-->回车-->在"软件包设置对话框"中输入mysql中"root"用户的密码-->回车-->再输一次密码-->回车,安装完成。 3 如何判断mysql是否安装成功 打开"终端窗口",输入"sudo service mysql restart"-->回车-->如果mysql启动成功,处于运行状态说明mysql安装成功。 4 让apache支持mysql 打开"终端窗口",输入"sudo apt-get install libapache2-mod-auth-mysql"-->回车-->安装成功,安装这个模块后,apache才能支持mysql。 5 让php支持mysql 打开"终端窗口",输入"sudo apt-get install php5-mysql"-->回车-->安装成功,安装这个模块后,php才能支持mysql。 6 登录mysql 打开"终端窗口",输入"mysql -u root -p"-->回车-->输入mysql中"root"用户的密码-->回车-->登录成功。

二安装sphinx

       01、安装全文搜索引擎 Sphinx 前,必须先安装 MySQL server 并设置数据库 root 用户(参考步骤一)        02、使用 apt-get 方法直接安装 Sphinx:

  1. apt-get install sphinxsearch

复制代码

       03、创建全文搜索引擎 Sphinx 的配置文件:

  1. cp /etc/sphinxsearch/sphinx.conf.sample /etc/sphinxsearch/sphinx.conf
  2. vi /etc/sphinxsearch/sphinx.conf

复制代码

              配置全文搜索引擎 Sphinx 的配置文件:

  1. sql_user = test
  2. sql_pass =
  3. # compat_sphinxql_magics = 1

复制代码

              将以上代码改为

  1. sql_user = root
  2. sql_pass = 您的数据库 root 用户密码
  3. compat_sphinxql_magics = 0

复制代码

       04、开启 sphinxsearch 功能:

  1. vi /etc/default/sphinxsearch

复制代码

              将其中的

  1. START=no

复制代码

              改为

  1. START=yes

复制代码

       05、创建 test 数据库:

代码语言:javascript
复制
root:~# mysql -u root -p

Enter password: 键入您的数据库 root 用户密码

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20177
Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>create database test;

Query OK, 1 row affected (0.00 sec)

mysql> use test;

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> exit

Bye

root:~#

复制代码

       06、将 test 数据库范例文件

  1. /etc/sphinxsearch/example.sql

复制代码

              下载到本地计算机        07、导入example.sql

mysql -u root -p你的root密码 -Dtest < /etc/sphinxsearch/example.sql

              说明 example.sql 文件导入 test 数据库成功        08、建立全文搜索引擎 Sphinx 的索引:

  1. indexer --all

复制代码

1.jpg
1.jpg

        09、启动全文搜索引擎 Sphinx 服务:

代码语言:javascript
复制
root:~# service sphinxsearch start

Starting sphinxsearch: Sphinx 2.0.4-id64-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/etc/sphinxsearch/sphinx.conf'...
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'test1'
precaching index 'test1stemmed'                             
WARNING: multiple addresses found for 'localhost', using the first one (ip=127.0.0.1)
precaching index 'rt'
precached 3 indexes in 0.001 sec
sphinxsearch.

root:~# 

复制代码

代码语言:javascript
复制
root:~# /usr/bin/search test

Sphinx 2.0.4-id64-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/etc/sphinxsearch/sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
    id=1
    group_id=1
    group_id2=5
    date_added=2014-12-22 15:30:18
    title=test one
    content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
    id=2
    group_id=1
    group_id2=6
    date_added=2014-12-22 15:30:18
    title=test two
    content=this is my test document number two
3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
    id=4
    group_id=2
    group_id2=8
    date_added=2014-12-22 15:30:18
    title=doc number four
    content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

index 'test1stemmed': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
    id=1
    group_id=1
    group_id2=5
    date_added=2014-12-22 15:30:18
    title=test one
    content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2421, group_id=1, date_added=Mon Dec 22 15:30:18 2014
    id=2
    group_id=1
    group_id2=6
    date_added=2014-12-22 15:30:18
    title=test two
    content=this is my test document number two
3. document=4, weight=1442, group_id=2, date_added=Mon Dec 22 15:30:18 2014
    id=4
    group_id=2
    group_id2=8
    date_added=2014-12-22 15:30:18
    title=doc number four
    content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

index 'rt': search error: failed to open /var/lib/sphinxsearch/data/rt.sph: No such file or directory.

root:~#
     

复制代码

       11、好啦,一切 OK

三测试

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年07月23日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档