我的MySQL數據庫版本5.1.38-rc。sphinx-0.9.9最新穩定版。Linux版本centos 5.4
安裝:(utf8)
#先解壓縮
tar zxvf MySQL-5.1.38.tar.gz
tar zxvf sphinx-0.9.9.tar.gz
先將/soft/sphinx-0.9.9/mysqlse下的文件復制至/soft/MySQL-5.1.38/storage/sphinx
cd sphinx-0.9.9/
cp -rf sphinx-0.9.9/mysqlse MySQL-5.1.38/storage/sphinx
查看目錄下是否有指定的文件。
然後先編譯安裝MySQL:
cd MySQL-5.1.38/
./configure --with-plugins=sphinx --prefix=/usr/local/MySQL/ --with-charset=utf8 --with-extra-charsets=all --enable-thread-safe-clIEnt --enable-assembler --with-readline --with-big-tables
--with-plugins=sphinx 一定要加入這條參數。意思是讓他支持我們的sphinx數據擴展,與MySQL-5.1.38/storage/sphinx 下的目錄名字保持一致。
又出錯error: No curses/termcap library found錯誤。
yum install libncurses5-dev
安裝這個先,繼續:
再出現個錯誤:error: unknown plugin: sphinx
執行
sh BUILD/autorun.sh
繼續出錯:BUILD/autorun.sh: line 23: aclocal: command not found
需要安裝automake,yum install automake,yum install libtool繼續執行:
無錯了。
在MySQL安裝目錄check下sphinx插件
./configure -h | grep sphinx
Plugin Name: sphin
然後再 重新編譯configure:
./configure --with-plugins=sphinx --prefix=/usr/local/MySQL/ --with-charset=utf8 --with-extra-charsets=complex --enable-thread-safe-clIEnt --enable-assembler --with-readline --with-big-tables --with-embedded-server --enable-local-infile
編譯提示:Thank you for choosing MySQL!
看來是ok了,make && make install
增加MySQL用戶並添加進組。
/usr/sbin/groupadd MySQL
/usr/sbin/useradd -g mysql MySQL
chmod +w /usr/local/MySQL
chown -R mysql:mysql /usr/local/MySQL
cd ../
創建MySQL數據庫存放目錄
mkdir -p /storage/MySQL/3306/data/
chown -R mysql:mysql /storage/MySQL/
以MySQL用戶帳號的身份建立數據表:
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/storage/mysql/3306/data --user=MySQL
創建my.cnf配置文件:(如果以前使用的是innodb數據擴展)注意的是將原來的innodb配置數據參數刪除或注釋)
vi /storage/MySQL/3306/my.cnf
[clIEnt]
default-character-set = utf8
port = 3306
socket = /tmp/MySQL.sock
[MySQL]
prompt="(\u:www.yzz.com:)[\d]> "
no-auto-rehash
[MySQLd]
default-character-set = utf8
user = MySQL
pid-file = /storage/mysql/3306/MySQL.pid
port = 3306
socket = /tmp/MySQL.sock
basedir = /usr/local/MySQL
datadir = /storage/MySQL/3306/data
open_files_limit = 10240
back_log = 600
max_connections = 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_b?r_size = 2M
join_b?r_size = 2M
thread_cache_size = 300
thread_concurrency = 8
qry_cache_size = 32M
qry_cache_limit = 2M
qry_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_qry_time = 1
log_long_format
log-bin = /storage/MySQL/3306/binlog
log = /storage/MySQL/3306/data
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_b?r_size = 256M
read_b?r_size = 1M
read_rnd_b?r_size = 16M
bulk_insert_b?r_size = 64M
myisam_sort_b?r_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
#innodb_additional_mem_pool_size = 16M
#innodb_b?r_pool_size = 2048M
#innodb_data_file_path = ibdata1:1024M:autoextend
#innodb_file_io_threads = 4
#innodb_thread_concurrency = 8
#innodb_flush_log_at_trx_commit = 2
#innodb_log_b?r_size = 16M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120
#innodb_file_per_table = 0
[MySQLdump]
quick
max_allowed_packet = 32M
創建管理MySQL數據庫的shell腳本:
vi /storage/mysql/3306/MySQL
#!/bin/sh MySQL_port=3306
MySQL_username="admin"
mysql_passWord="12345678" function_start_MySQL()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/storage/mysql/${MySQL_port}/my.cnf 2>&1 > /dev/null &
} function_stop_MySQL()
{
printf "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_passWord} -S /tmp/MySQL.sock shutdown
} function_restart_MySQL()
{
printf "Restarting MySQL...\n"
function_stop_MySQL
sleep 5
function_start_MySQL
} function_kill_MySQL()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${MySQL_port} | awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${MySQL_port} | awk '{printf $2}')
} if [ "$1" = "start" ]; then
function_start_MySQL
elif [ "$1" = "stop" ]; then
function_stop_MySQL
elif [ "$1" = "restart" ]; then
function_restart_MySQL
elif [ "$1" = "kill" ]; then
function_kill_MySQL
else
printf "Usage: /storage/mysql/${mysql_port}/MySQL {start|stop|restart|kill}\n"
fi
賦予shell腳本可執行權限:
chmod +x /storage/mysql/3306/MySQL
把MySQL服務加入啟動項:
cp -rf /usr/local/mysql/share/mysql/mysql.server /etc/init.d/MySQLd
啟動MySQL:
/storage/mysql/3306/MySQL start
/usr/local/mysql/bin/mysql -u root -p -S /tmp/MySQL.sock #套接子文件
輸入以下SQL語句,創建一個具有root權限的用戶(admin)和密碼(12345678):
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
運行show engines;,看是不是有一個叫sphinx的engine,有的話就表示sphinxSE(MySQL的sphinx引擎)安裝正常了.(看support的sphinx是否yes。代表正常)
接下來安裝sphinx:
cd /soft/sphinx-0.9.9,運行
ldconfig /usr/local/mysql/lib/MySQL
ldconfig /usr/local/mysql/incl?/MySQL
./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/MySQL
make && make install
安裝完成後
將sphinx.conf.dist拷貝/usr/local/sphinx/etc/sphinx.conf
cp -rf sphinx.conf.dist /usr/local/sphinx/etc/sphinx.conf
sphinx.conf配置代碼:注意# 源 src1是utf8編碼,test1為src1索引。src2是gbk編碼,test2為src2索引。
##### 源 ###########
source src1
{
type = MySQL
sql_host = localhost
sql_user = admin
sql_pass = 12345678
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_sock = /tmp/MySQL.sock
sql_qry_pre = SET NAMES UTF8
sql_qry_pre = SET SESSION qry_cache_type=OFF
sql_qry_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
#sql_qry_range = SELECT MIN(id),MAX(id) FROM documents
#sql_range_step = 1000
#sql_qry = SELECT * FROM documents WHERE id>=$start AND id<=$send
#####以下是用來過濾或條件查詢的屬性############
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_ranged_throttle = 1000
sql_qry_info = SELECT * FROM documents WHERE id=$id
}
### 索引 ###
index test1
{
####聲明索引源
source = src1
path = /usr/local/sphinx/var/data/test1
docinfo = extern
mlock = 0
morphology = none
#### 索引的詞最小長度
min_Word_len = 1
charset_type = utf-8
Html_strip = 0
##### 字符表,注意:如使用這種方式,則sphinx會對中文進行單字切分,
##### 即進行字索引,若要使用中文分詞,必須使用其他分詞插件如 coreseek,sfc
charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z,\
A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6,\
U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101,\
U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109,\
U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F,\
U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, \
U+0116->U+0117,U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D,\
U+011D,U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, \
U+0134->U+0135,U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, \
U+013C,U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, \
U+0143->U+0144,U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, \
U+014B,U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, \
U+0152->U+0153,U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159,\
U+0159,U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, \
U+0160->U+0161,U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, \
U+0167,U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, \
U+016E->U+016F,U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175,\
U+0175,U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, \
U+017B->U+017C,U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, \
U+0430..U+044F,U+05D0..U+05EA, U+0531..U+0556->U+0561..U+0586, U+0561..U+0587, \
U+0621..U+063A, U+01B9,U+01BF, U+0640..U+064A, U+0660..U+0669, U+066E, U+066F, \
U+0671..U+06D3, U+06F0..U+06FF,U+0904..U+0939, U+0958..U+095F, U+0960..U+0963, \
U+0966..U+096F, U+097B..U+097F,U+0985..U+09B9, U+09CE, U+09DC..U+09E3, U+09E6..U+09EF, \
U+0A05..U+0A39, U+0A59..U+0A5E,U+0A66..U+0A6F, U+0A85..U+0AB9, U+0AE0..U+0AE3, \
U+0AE6..U+0AEF, U+0B05..U+0B39,U+0B5C..U+0B61, U+0B66..U+0B6F, U+0B71, U+0B85..U+0BB9, \
U+0BE6..U+0BF2, U+0C05..U+0C39,U+0C66..U+0C6F, U+0C85..U+0CB9, U+0CDE..U+0CE3, \
U+0CE6..U+0CEF, U+0D05..U+0D39, U+0D60,U+0D61, U+0D66..U+0D6F, U+0D85..U+0DC6, \
U+1900..U+1938, U+1946..U+194F, U+A800..U+A805,U+A807..U+A822, U+0386->U+03B1, \
U+03AC->U+03B1, U+0388->U+03B5, U+03AD->U+03B5,U+0389->U+03B7, U+03AE->U+03B7, \
U+038A->U+03B9, U+0390->U+03B9, U+03AA->U+03B9,U+03AF->U+03B9, U+03CA->U+03B9, \
U+038C->U+03BF, U+03CC->U+03BF, U+038E->U+03C5,U+03AB->U+03C5, U+03B0->U+03C5, \
U+03CB->U+03C5, U+03CD->U+03C5, U+038F->U+03C9,U+03CE->U+03C9, U+03C2->U+03C3, \
U+0391..U+03A1->U+03B1..U+03C1,U+03A3..U+03A9->U+03C3..U+03C9, U+03B1..U+03C1, \
U+03C3..U+03C9, U+0E01..U+0E2E,U+0E30..U+0E3A, U+0E40..U+0E45, U+0E47, U+0E50..U+0E59, \
U+A000..U+A48F, U+4E00..U+9FBF,U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \
U+2F800..U+2FA1F, U+2E80..U+2EFF,U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \
U+3040..U+309F, U+30A0..U+30FF,U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \
U+3130..U+318F, U+A000..U+A48F,U+A490..U+A4CF
min_prefix_len = 0
min_infix_len = 1
ngram_len = 1
source src2
{
type = MySQL
sql_host = localhost
sql_user = admin
sql_pass = 12345678
sql_db = gbk
sql_port = 3306 # optional, default is 3306
sql_sock = /tmp/MySQL.sock
sql_qry_pre = SET NAMES gbk
sql_qry_pre = SET character_set_clIEnt=gbk
sql_qry_pre = SET character_set_connection=gbk
sql_qry_pre = SET character_set_results=utf8
sql_qry_pre = SET SESSION qry_cache_type=OFF
sql_qry_pre = REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
#sql_qry_range = SELECT MIN(id),MAX(id) FROM documents
#sql_range_step = 1000
#sql_qry = SELECT * FROM documents WHERE id>=$start AND id<=$send
#####以下是用來過濾或條件查詢的屬性############
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_ranged_throttle = 1000
sql_qry_info = SELECT * FROM documents WHERE id=$id
}
### 索引 ###
index test2
{
####聲明索引源
source = src2
path = /usr/local/sphinx/var/data/test2
docinfo = extern
mlock = 0
morphology = none
#### 索引的詞最小長度
min_Word_len = 1
charset_type = utf-8
Html_strip = 0
##### 字符表,注意:如使用這種方式,則sphinx會對中文進行單字切分,
##### 即進行字索引,若要使用中文分詞,必須使用其他分詞插件如 coreseek,sfc
charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z,\
A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6,\
U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101,\
U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109,\
U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F,\
U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, \
U+0116->U+0117,U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D,\
U+011D,U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, \
U+0134->U+0135,U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, \
U+013C,U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, \
U+0143->U+0144,U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, \
U+014B,U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, \
U+0152->U+0153,U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159,\
U+0159,U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, \
U+0160->U+0161,U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, \
U+0167,U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, \
U+016E->U+016F,U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175,\
U+0175,U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, \
U+017B->U+017C,U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, \
U+0430..U+044F,U+05D0..U+05EA, U+0531..U+0556->U+0561..U+0586, U+0561..U+0587, \
U+0621..U+063A, U+01B9,U+01BF, U+0640..U+064A, U+0660..U+0669, U+066E, U+066F, \
U+0671..U+06D3, U+06F0..U+06FF,U+0904..U+0939, U+0958..U+095F, U+0960..U+0963, \
U+0966..U+096F, U+097B..U+097F,U+0985..U+09B9, U+09CE, U+09DC..U+09E3, U+09E6..U+09EF, \
U+0A05..U+0A39, U+0A59..U+0A5E,U+0A66..U+0A6F, U+0A85..U+0AB9, U+0AE0..U+0AE3, \
U+0AE6..U+0AEF, U+0B05..U+0B39,U+0B5C..U+0B61, U+0B66..U+0B6F, U+0B71, U+0B85..U+0BB9, \
U+0BE6..U+0BF2, U+0C05..U+0C39,U+0C66..U+0C6F, U+0C85..U+0CB9, U+0CDE..U+0CE3, \
U+0CE6..U+0CEF, U+0D05..U+0D39, U+0D60,U+0D61, U+0D66..U+0D6F, U+0D85..U+0DC6, \
U+1900..U+1938, U+1946..U+194F, U+A800..U+A805,U+A807..U+A822, U+0386->U+03B1, \
U+03AC->U+03B1, U+0388->U+03B5, U+03AD->U+03B5,U+0389->U+03B7, U+03AE->U+03B7, \
U+038A->U+03B9, U+0390->U+03B9, U+03AA->U+03B9,U+03AF->U+03B9, U+03CA->U+03B9, \
U+038C->U+03BF, U+03CC->U+03BF, U+038E->U+03C5,U+03AB->U+03C5, U+03B0->U+03C5, \
U+03CB->U+03C5, U+03CD->U+03C5, U+038F->U+03C9,U+03CE->U+03C9, U+03C2->U+03C3, \
U+0391..U+03A1->U+03B1..U+03C1,U+03A3..U+03A9->U+03C3..U+03C9, U+03B1..U+03C1, \
U+03C3..U+03C9, U+0E01..U+0E2E,U+0E30..U+0E3A, U+0E40..U+0E45, U+0E47, U+0E50..U+0E59, \
U+A000..U+A48F, U+4E00..U+9FBF,U+3400..U+4DBF, U+20000..U+2A6DF, U+F900..U+FAFF, \
U+2F800..U+2FA1F, U+2E80..U+2EFF,U+2F00..U+2FDF, U+3100..U+312F, U+31A0..U+31BF, \
U+3040..U+309F, U+30A0..U+30FF,U+31F0..U+31FF, U+AC00..U+D7AF, U+1100..U+11FF, \
U+3130..U+318F, U+A000..U+A48F,U+A490..U+A4CF
min_prefix_len = 0
min_infix_len = 1
ngram_len = 1
# inherited source example
#
# all the parameters are copIEd from the parent source,
# and may then be overridden in this source definition
#source src1throttled : src1
#{
#sql_ranged_throttle = 100
#sql_qry_pre = SET NAMES UTF8
#sql_qry_pre = SET SESSION qry_cache_type=OFF
#sql_qry_pre =
#sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents \
#WHERE id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#}
# inherited source example
#
# all the parameters are copIEd from the parent source,
# and may then be overridden in this source definition
#source src2throttled : src2
#{
#sql_ranged_throttle = 100
#sql_qry_pre = SET NAMES gbk
#sql_qry_pre = SET SESSION qry_cache_type=OFF
#sql_qry_pre =
#sql_qry = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents \
#WHERE id>( SELECT max_doc_id FROM sph_counter WHERE counter_id=1 )
#}
#index test1stemmed : test1
#{
#source = src1throttled
#path = /usr/local/sphinx/var/data/test1stemmed
#morphology = none
#}
#index test2stemmed : test2
#{
#source = src2throttled
#path = /usr/local/sphinx/var/data/test2stemmed
#morphology = none
#}
######### 索引器配置 #####
indexer
{
#內存限制
mem_limit = 32M
}
############ sphinx 服務進程 ########
searchd
{
port = 3312 #指定端口為3312.如果不加port參數。sphinx0.9.9版本默認為9312
log = /usr/local/sphinx/var/log/searchd.log
qry_log = /usr/local/sphinx/var/log/qry.log
read_timeout = 5
clIEnt_timeout = 300
max_children = 30
pid_file = /usr/local/sphinx/var/log/searchd.pid
max_matches = 1000
### 是否支持無縫切換,做增量索引時通常需要
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_vals = 4096
加載索引
/usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all #all代表test1.test2.
注: 先要給libMySQLclIEnt.so.16 建立軟鏈接
ln -s /usr/local/mysql/lib/mysql/libmysqlclIEnt.so.16 /usr/lib/libMySQLclIEnt.so.16
再通過
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf 開啟索引監聽
為了下面測試方便,我們先將sphinx.conf自帶的example.sql腳本倒入的MySQL中
/usr/local/mysql/bin/MySQL < /usr/local/sphinx/etc/example.sql //建立了一個test庫,並建立了documents測試表和數據
/usr/local/mysql/bin/MySQL < /usr/local/sphinx/etc/gbk.sql
測試:CLI上測試 命令端測試。
在上一步中,我們建立了索引,現在我們對剛建立的索引進行測試。測試有兩種方式:CLI端和API調用
在CLI端上命令測試是使用sphinx自帶的搜索命令:search
###### 在表索引上檢索 “發生” 或者別的關鍵詞
[root@localhost sphinx]# /usr/local/sphinx/bin/search -c /usr/local/sphinx/etc/sphinx.conf 發生
gbk編碼
只需要修改my.cnf配置文件。
[clIEnt]
default-character-set = gbk
[MySQLd]
default-character-set = gbk
修改完後,重啟MySQL服務就行了。
進入mysql指令查看MySQL服務器編碼與查詢輸出編碼:
/usr/local/mysql/bin/MySQL -uroot -p
MySQL> SHOW VARIABLES LIKE 'character_set_%';
character_set_clIEnt =utf8 #客戶端編碼
character_set_connection=utf8 #客戶端與服務器連接時的編碼
character_set_database=gbk #數據庫編碼
character_set_results=utf8 #select 查詢後將gbk轉換成utf8