您好,登錄后才能下訂單哦!
使用hbase shell命令進(jìn)入hbase:
[root@abcdefghijklmnopqrstuvwxyzabcdefghijkl123456789012~]# hbase shell SLF4J: Class path contains multiple SLF4Jbindings. SLF4J: Found binding in[jar:file:/usr/hdp/2.4.3.0-227/hadoop/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in[jar:file:/usr/hdp/2.4.3.0-227/zookeeper/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Seehttp://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type[org.slf4j.impl.Log4jLoggerFactory] HBase Shell; enter 'help<RETURN>' forlist of supported commands. Type "exit<RETURN>" toleave the HBase Shell Version 1.1.2.2.4.3.0-227, rUnknown, FriSep 9 23:34:30 UTC 2016 hbase(main):001:0>
輸入help 查看幫助信息
hbase(main):001:0> help HBase Shell, version 1.1.2.2.4.3.0-227,rUnknown, Fri Sep 9 23:34:30 UTC 2016 Type 'help "COMMAND"', (e.g.'help "get"' -- the quotes are necessary) for help on a specificcommand. Commands are grouped. Type 'help"COMMAND_GROUP"', (e.g. 'help "general"') for help on acommand group. COMMAND GROUPS: Group name: general Commands: status, table_help, version, whoami …
查看服務(wù)器狀態(tài):
hbase(main):002:0> status 1 active master, 0 backup masters, 4servers, 0 dead, 20.5000 average load
查看版本信息
hbase(main):003:0> version 1.1.2.2.4.3.0-227, rUnknown, Fri Sep 9 23:34:30 UTC 2016
查看當(dāng)前用戶:
hbase(main):004:0> whoami root (auth:SIMPLE) groups: root
查看表相關(guān)命令的幫助信息:
hbase(main):005:0> table_help Help for table-reference commands. You can either create a table via 'create'and then manipulate the table via commands like 'put', 'get', etc. See the standard help information for howto use each of these commands. …
創(chuàng)建表
常用語(yǔ)法:create '[namespacename:]tablename' [ ,'columnfamilyname1' [ ,'columnfamilyname2, ....]]
詳細(xì)語(yǔ)法使用help -create 查看create語(yǔ)句
hbase(main):006:0> create 'test','fam1','fam2' 0 row(s) in 8.3530 seconds => Hbase::Table – test
使用list命令列出表名:
常用語(yǔ)法:list '[namespacename:]tablename]
詳細(xì)語(yǔ)法可以使用help 'list' 查看,list 后面可以跟正則表達(dá)式,列出符合表達(dá)式的表名
hbase(main):011:0> list 'test' –列出名為test的表名 TABLE test 1 row(s) in 0.0110 seconds => ["test"] hbase(main):012:0> list 'tes.*'—列出以名稱(chēng)tes開(kāi)頭的表名 TABLE test test:testtable 2 row(s) in 0.0150 seconds => ["test","test:testtable"] hbase(main):013:0> list 'default:.*' –列出default命名空間下的表名 TABLE ambarismoketest test 2 row(s) in 0.0150 seconds => ["ambarismoketest","test"] hbase(main):014:0> list 'test:.*' –列出test這個(gè)命名空間下的表名 TABLE test:testtable 1 row(s) in 0.0140 seconds => ["test:testtable"]
使用desc命令查看指定表的具體信息(desc等同于describe)
語(yǔ)法:desc '[namespacename:]tablename'
describe '[namespacename:]tablename'
詳細(xì)語(yǔ)法使用help 'describe'查看
hbase(main):016:0> desc 'test' 查看test這張表的信息 Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME => 'fam1', BLOOMFILTER =>'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRE SSION => 'NONE', MIN_VERSIONS => '0',BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} {NAME => 'fam2', BLOOMFILTER =>'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRE SSION => 'NONE', MIN_VERSIONS => '0',BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} 2 row(s) in 0.1710 seconds hbase(main):017:0> desc 'test:testtable'查看test命名空間下testtable這張表的信息 Table test:testtable is ENABLED test:testtable COLUMN FAMILIES DESCRIPTION {NAME => 'colfam1', BLOOMFILTER =>'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COM PRESSION => 'NONE', MIN_VERSIONS =>'0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} {NAME => 'colfam2', BLOOMFILTER =>'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COM PRESSION => 'NONE', MIN_VERSIONS =>'0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} {NAME => 'colfam3', BLOOMFILTER =>'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COM PRESSION => 'NONE', MIN_VERSIONS =>'0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} 3 row(s) in 0.0290 seconds
使用put插入數(shù)據(jù)
常用語(yǔ)法:put '[namespacename:]tablename' , 'rowkey' , 'columnfamilyname[:column]' , 'value'
詳細(xì)語(yǔ)法使用help 'put'查看
hbase(main):002:0> put'test','row2','fam1:a','value' 0 row(s) in 0.3760 seconds hbase(main):003:0> put 'test','row1','fam1:a','value' 0 row(s) in 0.3760 seconds hbase(main):004:0> put 'test','row1','fam2:a','value' 0 row(s) in 0.3760 seconds hbase(main):005:0> put'test','row2','fam2:a','value' 0 row(s) in 0.3760 seconds
使用scan查看全表數(shù)據(jù)
常用語(yǔ)法:scan '[namespacename:]tablename'
詳細(xì)語(yǔ)法使用help 'scan'查看
hbase(main):002:0> scan 'test' ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504767451331, value=value row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row(s) in 0.1120 seconds
查看指定列的數(shù)據(jù):
hbase(main):004:0> scan 'test',{COLUMNS=> 'fam1:a'} ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504767451331, value=value row2 column=fam1:a,timestamp=1504767600686, value=value 2 row(s) in 0.2390 seconds hbase(main):021:0> get 'test','row1' COLUMN CELL fam1:a timestamp=1504768075731, value=\x00\x00\x00\x00\x00\x00\x00\x02 fam2:a timestamp=1504767471977, value=value 2 row(s) in 0.1110 seconds
使用get查詢數(shù)據(jù):
語(yǔ)法:get '[namespacename:]tablename' , 'rowkey' [, 'columnfamliyname[:column]']
詳細(xì)語(yǔ)法使用help 'get'查看
hbase(main):024:0> get'test','row1','fam1' COLUMN CELL fam1:a timestamp=1504768075731, value=\x00\x00\x00\x00\x00\x00\x00\x02 1 row(s) in 0.0690 seconds hbase(main):026:0> get 'test','row1','fam1:a' COLUMN CELL fam1:a timestamp=1504768075731, value=\x00\x00\x00\x00\x00\x00\x00\x02 1 row(s) in 0.0430 seconds
使用delete刪除數(shù)據(jù)
常用語(yǔ)法:delete '[namespacename:]tablename' , 'rowkey' , 'columnfamliyname:column'
當(dāng)表中存在只制定了columnfamily沒(méi)有具體制定column的數(shù)據(jù)時(shí),delete可以這么用
delete '[namespacename:]tablename' , 'rowkey' , 'columnfamliyname',不存在這樣的數(shù)據(jù),使用這樣的語(yǔ)句不會(huì)刪除數(shù)據(jù)。
更詳細(xì)的語(yǔ)法使用help 'delete'查看
hbase(main):008:0> delete'test','row1','fam1:a' 0 row(s) in 0.3370 seconds hbase(main):009:0> scan 'test' ROW COLUMN+CELL row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row(s) in 0.0850 seconds
使用incr增加數(shù)據(jù)(默認(rèn)使用counter實(shí)現(xiàn)遞增)
常用語(yǔ)法:incr '[namespacename:]tablename' , 'rowkey' , 'columnfamilyname:column'
更詳細(xì)的語(yǔ)法使用help 'incr'查看
hbase(main):012:0> incr'test','row1','fam1:a' COUNTER VALUE = 1 0 row(s) in 1.1700 seconds hbase(main):013:0> scan 'test' ROW COLUMN+CELL row1 column=fam1:a,timestamp=1504768054892, value=\x00\x00\x00\x00\x00\x00\x00\x01 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014,value=value 2 row(s) in 0.0410 seconds hbase(main):014:0> incr'test','row1','fam1:a' COUNTER VALUE = 2 0 row(s) in 0.0480 seconds hbase(main):015:0> scan 'test' ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768075731,value=\x00\x00\x00\x00\x00\x00\x00\x02 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row(s) in 0.0770 seconds
使用get_counter查看當(dāng)前的counter值:
hbase(main):027:0> get_counter'test','row1','fam1:a' COUNTER VALUE = 2
使用put更新數(shù)據(jù):
hbase(main):029:0> scan 'test' ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768075731,value=\x00\x00\x00\x00\x00\x00\x00\x02 row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row(s) in 0.0270 seconds hbase(main):030:0> put'test','row1','fam1:a','newvalue' 0 row(s) in 0.0250 seconds hbase(main):031:0> scan 'test' ROW COLUMN+CELL row1 column=fam1:a, timestamp=1504768397480, value=newvalue row1 column=fam2:a, timestamp=1504767471977, value=value row2 column=fam1:a, timestamp=1504767600686, value=value row2 column=fam2:a, timestamp=1504767715014, value=value 2 row(s) in 0.0760 seconds
使用is_enabled/is_disabled查看表是否被啟用/禁用
hbase(main):032:0> is_enable 'test' NoMethodError: undefined method `is_enable'for #<Object:0x15d114ce> hbase(main):033:0> is_enabled 'test' true 0 row(s) in 0.1180 seconds hbase(main):034:0> is_disabled 'test' false 0 row(s) in 0.0190 seconds
使用disable禁用表
hbase(main):001:0> disable 'test' 0 row(s) in 4.7170 seconds hbase(main):002:0> is_disabled 'test' true 0 row(s) in 0.0210 seconds
使用enbale啟用表
hbase(main):003:0> enable 'test' 0 row(s) in 2.2910 seconds hbase(main):004:0> is_enabled 'test' true 0 row(s) in 0.0180 seconds
刪除fam1這個(gè)columnfamily:
hbase(main):007:0> alter'test',{NAME=>'fam1',METHOD=>'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.1980 seconds hbase(main):008:0> desc 'test' Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME => 'fam2', BLOOMFILTER => 'ROW',VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE',DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRE SSION => 'NONE', MIN_VERSIONS => '0',BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE =>'0'} 1 row(s) in 0.0350 seconds
清空表數(shù)據(jù):
hbase(main):009:0> truncate 'test' Truncating 'test' table (it may take awhile): -Disabling table... -Truncating table... 0 row(s) in 3.6540 seconds hbase(main):010:0> scan 'te
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。