找到sphinx 的配置目录
cd /usr/local/sphinx/etc
复制sphinx.conf.dist并重命名
cp sphinx.conf.dist sphinx.conf
修改配置如下:
vi sphinx.conf
# data source type. mandatory, no default value
# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
type = mysql
#####################################################################
## SQL settings (for 'mysql' and 'pgsql' types)
#####################################################################
# some straightforward parameters for SQL source types
sql_host = localhost
sql_user = root
sql_pass = root
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
数据库导入
如果没有test数据库
create database test;
导入
mysql -u root -p </usr/local/sphinx/etc/example.sql
查看数据库
mysql> use test;
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| documents |
| tags |
+----------------+
2 rows in set (0.00 sec)
创建索引
cd /usr/local/sphinx/bin
./indexer --all