天天看點

MYSQL資料庫資料導入mongoDB

為測試MONDODB與MYSQL資料性能對比,需要先将存在mysql中的資料導入到mongodb中。

基本流程是:

1. 先将mysql資料導入到文本中

2.利用mongodb的資料導入工具将資料導入到mongodb中

具體操作如下:

1. 進入mysql資料資料庫,這裡的資料庫名稱是robinhood_afs. 将該資料庫中的資料表ENTRIES中的資料導出,儲存為/tmp/entries.json(有些其他路徑可能沒有權限寫,要注意),指令如下:

select * from ENTRIES into outfile '/tmp/entries.json' fields terminated by ',' lines terminated by '\n';

(總共查詢5240595rows,花費7min58.24sec)

2. 當第一步操作完成後,在/tmp目錄下,可以看到entries.json檔案。接下來需要調用mongodbimport工具将資料導入到mongodb,指令如下:

/usr/bin/mongoimport --port 27020 -d bigdata -c Entries  --type csv --ignoreBlanks  -f "id,parent_id,fullpath,owner,gr_name,size,blocks,last_access,last_mod,type,md_update,path_update,invalid,whitelisted,release_class,rel_cl_update" -file '/tmp/entries.json'

由此,遷移完成

參考:http://blog.sina.com.cn/s/blog_6c7f9f5101019oy7.html