大數(shù)據(jù)培訓(xùn)之HBase命令行基本操作匯總分享
2018-02-05 14:32:17
1993瀏覽
關(guān)于HBase是一個(gè)分布式的、面向列的開源數(shù)據(jù)庫,該技術(shù)來源于FayChang所撰寫的Google論文“Bigtable:一個(gè)結(jié)構(gòu)化數(shù)據(jù)的分布式存儲系統(tǒng)”。就像Bigtable利用了Google文件系統(tǒng)(FileSystem)所提供的分布式數(shù)據(jù)存儲一樣,HBase在Hadoop之上提供了類似于Bigtable的能力。HBase是Apache的Hadoop項(xiàng)目的子項(xiàng)目。HBase不同于一般的關(guān)系數(shù)據(jù)庫,它是一個(gè)適合于非結(jié)構(gòu)化數(shù)據(jù)存儲的數(shù)據(jù)庫。另一個(gè)不同的是HBase基于列的而不是基于行的模式。
[hdfs@hadoop1root]$hbase
Usage:hbase[][]
Options:
--configDIRConfigurationdirectiontouse.Default:./conf
--hostsHOSTSOverridethelistin'regionservers'file
Commands:
Somecommandstakearguments.Passnoargsor-hforusage.
shellRuntheHBaseshell
hbckRunthehbase'fsck'tool
hlogWrite-ahead-loganalyzer
hfileStorefileanalyzer
zkcliRuntheZooKeepershell
upgradeUpgradehbase
masterRunanHBaseHMasternode
regionserverRunanHBaseHRegionServernode
zookeeperRunaZookeeperserver
restRunanHBaseRESTserver
thriftRuntheHBaseThriftserver
thrift2RuntheHBaseThrift2server
cleanRuntheHBasecleanupscript
classpathDumphbaseCLASSPATH
mapredcpDumpCLASSPATHentriesrequiredbymapreduce
peRunPerformanceEvaluation
lttRunLoadTestTool
versionPrinttheversion
CLASSNAMERuntheclassnamedCLASSNAME
??進(jìn)入命令行
[root@hadoop1~]#hbaseshell
??退出命令行
hbase(main):001:0>exit
??查看全部表
hbase(main):001:0>listTABLE0row(s)in1.9500seconds
=>[]
??創(chuàng)建表
create'表名稱','列名稱1',...,'列名稱n'
eg:建立一個(gè)表scores,有兩個(gè)列族grad和courese。
hbase(main):004:0>create'scores','grad','courese'
0row(s)in1.5820seconds
=>Hbase::Table-scores
hbase(main):005:0>list
TABLE
scores
1row(s)in0.0080seconds
=>["scores"]
??添加記錄
put'表名','行鍵名','列名','單元格值','時(shí)間戳'
時(shí)間戳可以省略。
hbase(main):009:0>put'scores','Tom','grad:','5'
hbase(main):011:0>put'scores','Tom','courese:math','100'
hbase(main):012:0>put'scores','Tom','courese:art','100'
hbase(main):013:0>put'scores','Mark','grad','6'
hbase(main):014:0>put'scores','Mark','courese:english','120'
hbase(main):015:0>put'scores','Mark','courese:chinese','108'
??查找某條記錄
hbase(main):020:0>get'scores','Mark'
COLUMNCELL
courese:chinesetimestamp=1435491529683,value=108
courese:englishtimestamp=1435491508206,value=120
grad:timestamp=1435491484521,value=6
3row(s)in0.0520seconds
hbase(main):021:0>get'scores','Mark','grad'
COLUMNCELL
grad:timestamp=1435491484521,value=6
1row(s)in0.0390seconds
??統(tǒng)計(jì)行數(shù)
hbase>count'ns1:t1'
hbase>count't1'
hbase>count't1',INTERVAL=>100000
hbase>count't1',CACHE=>1000
hbase>count't1',INTERVAL=>10,CACHE=>1000
統(tǒng)計(jì)一般比較耗時(shí),使用mapreduce進(jìn)行統(tǒng)計(jì),統(tǒng)計(jì)結(jié)果會緩存,默認(rèn)是10行,統(tǒng)計(jì)間隔默認(rèn)是1000行。
hbase(main):038:0>count'scores'
2row(s)in0.0290seconds
=>2
??修改表結(jié)構(gòu)
增加一列族
hbase(main):048:0>alter'scores',NAME=>'info'
Updatingallregionswiththenewschema...
0/1regionsupdated.
1/1regionsupdated.
Done.
0row(s)in2.4330seconds
刪除一個(gè)列族
hbase(main):053:0>alter'scores',NAME=>'NAME=info',METHOD=>'delete'
Updatingallregionswiththenewschema...
0/1regionsupdated.
1/1regionsupdated.
Done.
0row(s)in2.4670seconds
hbase(main):055:0>alter'scores','delete'=>'courese'
??不過不能刪除掉,先disable'scores',修改完之后再enable'scores'。
??刪除表
先禁用表
hbase(main):057:0>disable'scores'
然后刪除表
hbase(main):057:0>drop'scores'
??刪除指定數(shù)據(jù)
delete'scores','Mark','courese:english'
??刪除整行
deleteall'表名','行鍵'
deleteall'scores','Mark'(慎用)
??清空表:表結(jié)構(gòu)仍然在
truncate'scores'
最后想要了解更多關(guān)于大數(shù)據(jù)發(fā)展前景趨勢,請關(guān)注扣丁學(xué)堂官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育平臺為您提供權(quán)威的大數(shù)據(jù)視頻教程系統(tǒng),通過千鋒旗下金牌講師在線錄制的大數(shù)據(jù)培訓(xùn)視頻教程系統(tǒng),讓你快速掌握大數(shù)據(jù)從入門到精通大數(shù)據(jù)開發(fā)實(shí)戰(zhàn)技能??鄱W(xué)堂大數(shù)據(jù)學(xué)習(xí)群:209080834。
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“大數(shù)據(jù)培訓(xùn)資訊”的相關(guān)文章>>
標(biāo)簽: