經(jīng)驗(yàn)分享:社會(huì)工程學(xué)數(shù)據(jù)庫搭建TIPS
最近一直在搞社工庫的搭建。網(wǎng)上這方面也有很多文章,但是很少涉及到細(xì)節(jié),在此與大家分享一些個(gè)人心得。
測(cè)試環(huán)境
測(cè)試壞境:windows server 2012(x64,16G 內(nèi)存) ,MySQL-5.0.90,php-5.2.14-Win32
準(zhǔn)備工具:coreseek-4.1-win32,Phantom 牛的源碼
搭建過程
1,首先查看要索引表的字段,以便于在csft_mysql.conf 文件中配置

我們修改csft_myxql.conf 文件。(coreseek 3.2.14 不支持sql_query_string =)

注意Sql_query 中的字段必須和我們nan1 表中一致、
要支持cjk(中,日,韓簡(jiǎn)寫)的查詢我們必須用它的專用charset_table
因此我們應(yīng)當(dāng)在index mysql 中加入charset_table(因數(shù)據(jù)量過長(zhǎng)此處就省去,請(qǐng)查看我
的配置文件)
2,讓sphinx 支持實(shí)時(shí)索引,以便于我們后期解決某個(gè)問題。后來發(fā)現(xiàn)還是沒有解決成功
什么是實(shí)時(shí)索引就不再纂述了:)

應(yīng)當(dāng)添加到index mysql 下方,具體請(qǐng)參照配置文件。修改好配置文件后請(qǐng)用UTF-8 without
BOM 格式保存以便程序讀取配置文件。
3,建立索引,并啟動(dòng)

因?yàn)槭菧y(cè)試數(shù)據(jù)量很小,因此程序啟動(dòng)成功
若數(shù)據(jù)量超過1 億將顯示內(nèi)存不足

將mem_limit = 1M 設(shè)置成1M 重新建立索引,若還是提示內(nèi)存不足
將表數(shù)據(jù)分割,依賴實(shí)時(shí)索引動(dòng)態(tài)插入數(shù)據(jù)(ps:如果大牛還有更好的辦法請(qǐng)與我聯(lián)系)
因測(cè)試我們用nan4 表做演示
此處我們有三種方法來分割表
Code:create table nan3 select distinct
firstname,lastname,email,username,password,hash,addr1,addr2,jumin1,jumin2,sex,s
sn from nan4;
create table nan3 Select
firstname,lastname,email,username,password,hash,addr1,addr2,jumin1,jumin2,sex,s
sn from nan4 group by
firstname,lastname,email,username,password,hash,addr1,addr2,jumin1,jumin2,sex,s
sn from nan4;
//兩句代碼效果都一樣去除username,password....sex 中內(nèi)容相同的插入nan3 表,為有人
不理解我是意思,我截圖示之,本人表達(dá)能力有問題

Group by 語句差不多;
昨晚喳喳同學(xué)告訴了我一個(gè)直接去除表中重復(fù)內(nèi)容的語句我也貼上來,感謝他了(ps:和他研究了一晚上,沒辦法啊,人笨。)
Code:delete from temps where id in (select id from (select
id from temps as s where (select count(*) from temps as a
where a.username=s.username and a.password =s.password)>1
and id not in(select id from(select id,count(distinct username,
password) from temps as s where (select count(*) from test4
as a where a.username=s.username and a.password =s.password
)>1 group by username) as sss))as ttt)
注意:此處id:需為自增ID
分割表時(shí)不要用limit 參數(shù)與distinct 參數(shù)混用容易造成卡死,且得多次去重
create table tempss select * from nan3 limit 0,3;
create table temp select * from nan3 limit 3,5;
create table tempss select * from nan3 limit 0,3;create table temp select * from nan3 limit 3,5;

OK,現(xiàn)在我們已經(jīng)分成兩個(gè)表,并手動(dòng)給兩個(gè)表添加自增ID(temp id 最大值為4,temps id 最小值為5),我們將一個(gè)temp 表建立索引,并啟動(dòng)

話說不知道是我人品的問題還是那啥,因此我們需要稍改一下search.php 的源碼

搜索結(jié)果

insert into temp select * from tempss;//將tempss 的數(shù)據(jù)插入到temp

插入后搜索結(jié)果



我對(duì)不起大家經(jīng)過我的測(cè)試實(shí)時(shí)索引重啟后還是出現(xiàn)內(nèi)存不足的情況,且只能修改我們索引
后的id 對(duì)應(yīng)字段參數(shù)值。(留待大牛解答了)
補(bǔ)充TIPS
如果你恰好有韓國(guó)的或者小日本的數(shù)據(jù)庫,又恰好的先導(dǎo)入進(jìn)去了(入庫沒啥好說的,數(shù)據(jù)庫編碼最好統(tǒng)一為utf8),編碼也設(shè)置成949
或者euckr

可能下面的語句能幫到您:
create table test4 select username ,password from test1 union
select username,password from test2;
//將test2 表與test1 表比較清除重復(fù)后插入test4 中;(ps:字段數(shù)據(jù)類型可
以不同)
ALTER TABLE test4 DEFAULT CHARACTER SET utf8 COLLATE utf8_gen
eral_ci;
//不解釋
alter table nan1 modify column username varchar(50); //修改username 的數(shù)據(jù)類型
alter table $table add $username varchar(50) null; //添加新字段
程序下載地址,提取碼4su4
參考文章
http://blog.csdn.net/rulev5/article/details/7572482
http://tesfans.org/using-sphinx-search-engine-with-chinese-japanese-and-korean-language-documents/
http://zone.wooyun.org/content/9377
歡迎志同道合的朋友與我交流:InN0t@outlook.com,作者:InN0t