您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關常用HBase shell命令有哪些,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
一:HBase
1.使用hbase 命令之前先檢查一下hbase是否運行正常,通過JPS查看進程
hadoop@master:/mysoftware/hbase-1.2.1/bin$ jps 4051 HQuorumPeer 3776 QuorumPeerMain 2818 NameNode 4149 HMaster 3140 SecondaryNameNode 2966 DataNode 4549 Jps 4304 HRegionServer 3365 ResourceManager
2.進入HBase shell 客戶端
hadoop@master:/mysoftware/hbase-1.2.1$ bin/hbase shell
二:HBase 基本命令概覽
HBase Shell的一些基本操作命令,列出了幾個常用的HBase Shell命令,如下:
名稱 | 命令表達式 |
創建表 | create '表名稱', '列名稱1','列名稱2','列名稱N' |
添加記錄 | put '表名稱', '行名稱', '列名稱:xxx', '值' |
查看記錄 | get '表名稱', '行名稱' |
查看表中的記錄總數 | count '表名稱' |
刪除記錄 | delete '表名' ,'行名稱' , '列名稱' |
刪除一張表 | 先要屏蔽該表,才能對該表進行刪除,第一步 disable '表名稱' 第二步 drop '表名稱' |
查看所有記錄 | scan "表名稱" |
查看某個表某個列中所有數據 | scan "表名稱" , ['列名稱:'] |
更新記錄 | 就是重寫一遍進行覆蓋 |
三:HBase基本命令小實用,以下步驟
四:.一般操作
1.查詢服務器狀態:status
hbase(main):002:0> status 1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
2.查詢Hbase版本:version
hbase(main):003:0> vesion NameError: undefined local variable or method `vesion' for #<Object:0x52ac9a2c>
五:DDL操作
1.創建一張表userinfo :create 'userinfo','name','age'
hbase(main):011:0> create 'userinfo','name','age' 0 row(s) in 1.3220 seconds => Hbase::Table - userinfo
2.列出所有表:list
hbase(main):013:0> list TABLE table1 userinfo 2 row(s) in 0.0230 seconds => ["table1", "userinfo"]
3.獲得表的描述:describe
hbase(main):014:0> describe 'userinfo' Table userinfo is ENABLED userinfo COLUMN FAMILIES DESCRIPTION {NAME => 'age', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSI ON => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'f alse', BLOCKCACHE => 'true'} {NAME => 'name', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESS ION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => ' false', BLOCKCACHE => 'true'} 2 row(s) in 0.0430 seconds
4.查看表是否存在:exists
hbase(main):017:0> exists 'table2' Table table2 does not exist 0 row(s) in 0.0210 seconds
5.判斷表是否為:‘enable’
hbase(main):018:0> is_enabled 'userinfo' true
6.判斷表是否為:‘disable’
hbase(main):019:0> is_disabled 'userinfo' false
7.刪除一個列族 disable alter enable
hbase(main):003:0> disable 'table1' 0 row(s) in 0.0230 seconds hbase(main):004:0> alter 'table1',{ NAME => 't2' , METHOD => 'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.2240 seconds hbase(main):005:0> enable 'table1' 0 row(s) in 1.2990 seconds
然后在查看該列是否刪除,看通過獲得表的描述查看,如下: 只剩下列 ‘t1‘。
hbase(main):006:0> describe 'table1' Table table1 is ENABLED table1 COLUMN FAMILIES DESCRIPTION {NAME => 't1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSIO N => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'fa lse', BLOCKCACHE => 'true'} 1 row(s) in 0.0290 seconds
8.刪除一個表:drop , 刪除表前,需要先屏蔽該表。
hbase(main):007:0> disable 'table1' 0 row(s) in 2.2910 seconds hbase(main):008:0> drop 'table1' 0 row(s) in 1.3030 seconds
六:DML操作
1.往userinfo中插入幾條記錄: put ’表名‘,’行名‘,’列族名:xxx‘,'value'
hbase(main):016:0> put 'userinfo','row1','name:col1','Berg' 0 row(s) in 0.0870 seconds hbase(main):017:0> put 'userinfo','row1','age:col2','22' 0 row(s) in 0.0180 seconds hbase(main):018:0> put 'userinfo','row2','name:col1','hadoophbase' 0 row(s) in 0.0190 seconds hbase(main):019:0> put 'userinfo','row2','age:col2','20' 0 row(s) in 0.0180 seconds
2.全表掃描:scan
hbase(main):001:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg row2 column=age:col2, timestamp=1463066598770, value=20 row2 column=name:col1, timestamp=1463066577206, value=hadoophbase
3. 獲得某一行的所有數據,也是獲得某一行名的所有數據
hbase(main):003:0> get 'userinfo', 'row1' COLUMN CELL age:col2 timestamp=1463066528653, value=22 name:col1 timestamp=1463066505217, value=Berg
4.獲得某行,某列族,某列的所有數據
hbase(main):004:0> get 'userinfo','row1','name:col1' COLUMN CELL name:col1 timestamp=1463066505217, value=Berg 1 row(s) in 0.0190 seconds
5.更新一條記錄 : put( name:col1的值更改為: BergBergBerg )
hbase(main):009:0> put 'userinfo','row2','name:col1','BergBergBerg' 0 row(s) in 0.0720 seconds
獲取更新后的值:
hbase(main):011:0> get 'userinfo','row2','name:col1' COLUMN CELL name:col1 timestamp=1463067259346, value=BergBergBerg 1 row(s) in 0.0280 seconds
6.查詢表中有多少行:count
hbase(main):012:0> count 'userinfo' 2 row(s) in 0.0450 seconds => 2
7.刪除 某行 某列族的值:delete
hbase(main):023:0> delete 'userinfo','row2','age:col2' 0 row(s) in 0.0140 seconds hbase(main):024:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg row2 column=name:col1, timestamp=1463067259346, value=BergBergBerg 2 row(s) in 0.0300 seconds
8.刪除整行的值:deleteall
hbase(main):026:0> deleteall 'userinfo','row2' 0 row(s) in 0.0190 seconds hbase(main):027:0> scan 'userinfo' ROW COLUMN+CELL row1 column=age:col2, timestamp=1463066528653, value=22 row1 column=name:col1, timestamp=1463066505217, value=Berg 1 row(s) in 0.0320 seconds
9.給 row1 這行 age列,并使用counter實現遞增 : incr (好吧,做這里的時候有點怪,原因無他,列族名沒有取得好。。。。。)
hbase(main):024:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 1 0 row(s) in 0.0170 seconds hbase(main):025:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 2 0 row(s) in 0.0210 seconds hbase(main):026:0> incr 'userinfo','row1','age:id' COUNTER VALUE = 3 0 row(s) in 0.1270 seconds
獲取當前counter的值:
hbase(main):027:0> get_ get_auths get_counter get_splits get_table hbase(main):027:0> get_counter 'userinfo','row1','age:id' COUNTER VALUE = 3
10.將整個表清空:truncate
hbase(main):028:0> truncate 'userinfo' Truncating 'userinfo' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in 4.3360 seconds hbase(main):029:0> scan 'userinfo' ROW COLUMN+CELL 0 row(s) in 0.3490 seconds
關于“常用HBase shell命令有哪些”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。