Ubuntu系統,搭建mysql+sphinx環建
本文介紹下如何在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:
- apt-get install sphinxsearch
- cp /etc/sphinxsearch/sphinx.conf.sample /etc/sphinxsearch/sphinx.conf
- vi /etc/sphinxsearch/sphinx.conf
- sql_user = test
- sql_pass =
- # compat_sphinxql_magics = 1
- sql_user = root
- sql_pass = 您的資料庫 root 使用者密碼
- compat_sphinxql_magics = 0
- vi /etc/default/sphinxsearch
- START=no
- START=yes
- 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:~#
- /etc/sphinxsearch/example.sql
07、匯入example.sql
mysql -u root -p你的root密碼 -Dtest < /etc/sphinxsearch/example.sql
說明 example.sql 檔案匯入 test 資料庫成功08、建立全文搜尋引擎 Sphinx 的索引:
- indexer --all
09、啟動全文搜尋引擎 Sphinx 服務:
- 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:~#
- 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:~#
三測試