hbase shell命令
環境:
hadoop2.7.3
hbase1.x,如果還沒安裝hbase,請點選這裡安裝hbase
hbase shell常用命令
啟動hadoop及hbase
start-all.sh
start-hbase.sh
進入hbase shell命令
hbase shell
檢視所有表
hbase(main):003:0> list
TABLE
0 row(s) in 0.0500 seconds
=> []
最開始hbase還沒有任何表
建表
語法: create '表名','列族1','列族2'
hbase(main):004:0> create 'Student','baseInfo','schoolInfo'
0 row(s) in 1.3250 seconds
=> Hbase::Table - Student
檢視錶資訊
語法:desc '表名'
hbase(main):005:0> describe 'Student'
Table Student is ENABLED
Student
COLUMN FAMILIES DESCRIPTION
{NAME => 'baseInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false'
, KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER'
, COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE =>
'65536', REPLICATION_SCOPE => '0'}
{NAME => 'schoolInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'fals
e', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVE
R', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.0890 seconds
禁用/啟用表
檢視錶是否啟用
hbase(main):006:0> is_enabled 'Student'
true
0 row(s) in 0.0200 seconds
禁用表
hbase(main):007:0> disable 'Student'
0 row(s) in 2.2660 seconds
hbase(main):008:0> is_enabled 'Student'
false
0 row(s) in 0.0270 seconds
啟用表
hbase(main):009:0> enable 'Student'
0 row(s) in 1.2520 seconds
hbase(main):010:0> is_enabled 'Student'
true
0 row(s) in 0.0150 seconds
刪除表
刪除表之前,需先禁用表
hbase(main):012:0> disable 'Student'
0 row(s) in 2.2390 seconds
刪除表
hbase(main):013:0> drop 'Student'
0 row(s) in 1.2630 seconds
確認表是否已經被刪除
hbase(main):015:0> exists 'Student'
Table Student does not exist
0 row(s) in 0.0090 seconds
增刪改表
上一步已經刪除了Student表,現在先將表再次建立出來
hbase(main):016:0> create 'Student','baseInfo','schoolInfo'
0 row(s) in 2.2290 seconds
=> Hbase::Table - Student
新增列族
hbase(main):017:0> alter 'Student','teacherInfo'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.9380 seconds
hbase(main):018:0> describe 'Student'
Table Student is ENABLED
Student
COLUMN FAMILIES DESCRIPTION
{NAME => 'baseInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false'
, KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER'
, COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE =>
'65536', REPLICATION_SCOPE => '0'}
{NAME => 'schoolInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'fals
e', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVE
R', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536', REPLICATION_SCOPE => '0'}
{NAME => 'teacherInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'fal
se', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREV
ER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536', REPLICATION_SCOPE => '0'}
3 row(s) in 0.0130 seconds
刪除列族
刪除列族
hbase(main):019:0> alter 'Student',{NAME=>'teacherInfo', METHOD =>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.3900 seconds
檢視錶結構
hbase(main):020:0> describe 'Student'
Table Student is ENABLED
Student
COLUMN FAMILIES DESCRIPTION
{NAME => 'baseInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false'
, KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER'
, COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE =>
'65536', REPLICATION_SCOPE => '0'}
{NAME => 'schoolInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'fals
e', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVE
R', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.0180 seconds
插入/更新資料
語法:put ‘表名’, ‘行鍵’,‘列族:列’,‘值’
注意:如果新增資料的行鍵值、列族名、列名與原有資料完全相同(除了值之外),則相當於更新操作,否則為插入操作。
put插入一些資料
put 'Student', 'rowkey1','baseInfo:name','jim'
put 'Student', 'rowkey1','baseInfo:birthday','1990-01-09'
put 'Student', 'rowkey1','baseInfo:age','18'
put 'Student', 'rowkey1','schoolInfo:name','Havard'
put 'Student', 'rowkey1','schoolInfo:localtion','Boston'
put 'Student', 'rowkey2','baseInfo:name','jack'
put 'Student', 'rowkey2','baseInfo:birthday','1998-08-22'
put 'Student', 'rowkey2','baseInfo:age','21'
put 'Student', 'rowkey2','schoolInfo:name','yale'
put 'Student', 'rowkey2','schoolInfo:localtion','New Haven'
put 'Student', 'rowkey3','baseInfo:name','maike'
put 'Student', 'rowkey3','baseInfo:birthday','1995-01-22'
put 'Student', 'rowkey3','baseInfo:age','24'
put 'Student', 'rowkey3','schoolInfo:name','yale'
put 'Student', 'rowkey3','schoolInfo:localtion','New Haven'
put 'Student', 'wrowkey4','baseInfo:name','maike-jack'
put更新操作
hbase(main):021:0> put 'Student','rowkey1','baseInfo:name','tom'
0 row(s) in 0.0760 seconds
hbase(main):022:0> put 'Student','rowkey1','baseInfo:birthday','1990-01-01'
0 row(s) in 0.0710 seconds
hbase(main):024:0> put 'Student','rowkey1','baseInfo:age','29'
0 row(s) in 0.0080 seconds
刪除行資料
檢視行資料
hbase(main):042:0> get 'Student','rowkey3'
COLUMN CELL
baseInfo:age timestamp=1600789513388, value=24
baseInfo:birthday timestamp=1600789513369, value=1995-01-22
baseInfo:name timestamp=1600789513349, value=maike
schoolInfo:localtion timestamp=1600789513415, value=New Haven
schoolInfo:name timestamp=1600789513405, value=yale
1 row(s) in 0.0110 seconds
刪除指定行中指定列的資料
hbase(main):043:0> delete 'Student','rowkey3','baseInfo:name'
0 row(s) in 0.0240 seconds
再次檢視行資料
hbase(main):044:0> get 'Student','rowkey3'
COLUMN CELL
baseInfo:age timestamp=1600789513388, value=24
baseInfo:birthday timestamp=1600789513369, value=1995-01-22
schoolInfo:localtion timestamp=1600789513415, value=New Haven
schoolInfo:name timestamp=1600789513405, value=yale
1 row(s) in 0.0070 seconds
查詢
hbase中訪問資料有兩種基本的方式:
-
按指定rowkey獲取資料:get方法;
-
按指定條件獲取資料:scan方法。
scan
可以設定begin和end引數來訪問一個範圍內所有的資料。get本質上就是begin和end相等的一種特殊的scan。
GET查詢
按rowkey查詢
hbase(main):059:0> get 'Student','rowkey3'
COLUMN CELL
baseInfo:age timestamp=1600789513388, value=24
baseInfo:birthday timestamp=1600789513369, value=1995-01-22
schoolInfo:localtion timestamp=1600789513415, value=New Haven
schoolInfo:name timestamp=1600789513405, value=yale
1 row(s) in 0.0110 seconds
按rowkey和列族來查詢
hbase(main):060:0> get 'Student','rowkey3','baseInfo'
COLUMN CELL
baseInfo:age timestamp=1600789513388, value=24
baseInfo:birthday timestamp=1600789513369, value=1995-01-22
1 row(s) in 0.0070 seconds
按rowkey和列族中的某列來查詢
hbase(main):061:0> get 'Student','rowkey3','baseInfo:age'
COLUMN CELL
baseInfo:age timestamp=1600789513388, value=24
1 row(s) in 0.0090 seconds
hbase(main):062:0>
SCAN查詢
hbase(main):065:0> scan 'Student'
ROW COLUMN+CELL
rowkey1 column=baseInfo:age, timestamp=1600789446674, value=29
rowkey1 column=baseInfo:birthday, timestamp=1600789402212, value=1990-01-01
rowkey1 column=baseInfo:name, timestamp=1600789375235, value=tom
rowkey1 column=schoolInfo:localtion, timestamp=1600789503013, value=Boston
rowkey1 column=schoolInfo:name, timestamp=1600789500988, value=Havard
rowkey2 column=baseInfo:age, timestamp=1600789513297, value=21
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
rowkey2 column=baseInfo:name, timestamp=1600789513258, value=jack
rowkey2 column=schoolInfo:localtion, timestamp=1600789513328, value=New Haven
rowkey2 column=schoolInfo:name, timestamp=1600789513314, value=yale
rowkey3 column=baseInfo:age, timestamp=1600789513388, value=24
rowkey3 column=baseInfo:birthday, timestamp=1600789513369, value=1995-01-22
rowkey3 column=schoolInfo:localtion, timestamp=1600789513415, value=New Haven
rowkey3 column=schoolInfo:name, timestamp=1600789513405, value=yale
wrowkey4 column=baseInfo:name, timestamp=1600789515763, value=maike-jack
4 row(s) in 0.0180 seconds
hbase(main):068:0> scan 'Student',{COLUMN=>'baseInfo'}
ROW COLUMN+CELL
rowkey1 column=baseInfo:age, timestamp=1600789446674, value=29
rowkey1 column=baseInfo:birthday, timestamp=1600789402212, value=1990-01-01
rowkey1 column=baseInfo:name, timestamp=1600789375235, value=tom
rowkey2 column=baseInfo:age, timestamp=1600789513297, value=21
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
rowkey2 column=baseInfo:name, timestamp=1600789513258, value=jack
rowkey3 column=baseInfo:age, timestamp=1600789513388, value=24
rowkey3 column=baseInfo:birthday, timestamp=1600789513369, value=1995-01-22
wrowkey4 column=baseInfo:name, timestamp=1600789515763, value=maike-jack
4 row(s) in 0.0180 seconds
hbase(main):071:0> scan 'Student',{COLUMNS=>'baseInfo:birthday'}
ROW COLUMN+CELL
rowkey1 column=baseInfo:birthday, timestamp=1600789402212, value=1990-01-01
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
rowkey3 column=baseInfo:birthday, timestamp=1600789513369, value=1995-01-22
3 row(s) in 0.0190 seconds
STARTROW為開始行
STOPROW為結束行
LIMIT為限制查詢結果行數
VERSIONS版本數
hbase(main):003:0> scan 'Student', {COLUMNS=> 'baseInfo',STARTROW => 'rowkey2',STOPROW => 'wrowkey4'}
ROW COLUMN+CELL
rowkey2 column=baseInfo:age, timestamp=1600789513297, value=21
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
rowkey2 column=baseInfo:name, timestamp=1600789513258, value=jack
rowkey3 column=baseInfo:age, timestamp=1600789513388, value=24
rowkey3 column=baseInfo:birthday, timestamp=1600789513369, value=1995-01-22
2 row(s) in 0.0200 seconds
只顯示1條資料
hbase(main):007:0> scan 'Student', {COLUMNS=> 'baseInfo',STARTROW => 'rowkey2',STOPROW => 'wrowkey4',LIMIT=>1}
ROW COLUMN+CELL
rowkey2 column=baseInfo:age, timestamp=1600789513297, value=21
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
rowkey2 column=baseInfo:name, timestamp=1600789513258, value=jack
1 row(s) in 0.0090 seconds
查詢年齡等於24的資料
hbase(main):010:0> scan 'Student', FILTER=>"ValueFilter(=,'binary:24')"
ROW COLUMN+CELL
rowkey3 column=baseInfo:age, timestamp=1600789513388, value=24
1 row(s) in 0.0790 seconds
查詢包含字串yal的資料
hbase(main):011:0> scan 'Student', FILTER=>"ValueFilter(=,'substring:yal')"
ROW COLUMN+CELL
rowkey2 column=schoolInfo:name, timestamp=1600789513314, value=yale
rowkey3 column=schoolInfo:name, timestamp=1600789513405, value=yale
2 row(s) in 0.0270 seconds
查詢列包括birth和值包括1988的資料
hbase(main):012:0> scan 'Student', FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter ValueFilter(=,'substring:1998')"
ROW COLUMN+CELL
rowkey2 column=baseInfo:birthday, timestamp=1600789513285, value=1998-08-22
1 row(s) in 0.0630 seconds
PrefixFilter
用於對Rowkey的字首進行判斷:
hbase(main):013:0> scan 'Student', FILTER=>"PrefixFilter('wr')"
ROW COLUMN+CELL
wrowkey4 column=baseInfo:name, timestamp=1600789515763, value=maike-jack
1 row(s) in 0.0190 seconds
參考:https://github.com/heibaiying/BigData-Notes/blob/master/notes/Hbase_Shell.md
完成!enjoy it!
相關文章
- HBase 系列(五)——HBase常用 Shell 命令
- hbase - [03] 客戶端常用命令(hbase shell)客戶端
- hbase之hbase shell
- Hbase shell的基本操作
- Shell命令
- Hive shell 命令Hive
- HDFS shell命令
- Shell printf 命令
- Shell test 命令
- Shell命令列命令列
- shell命令(一)
- 常用shell 命令
- HBase Shell 十大花式玩兒法
- HBase的常用命令
- shell 基礎命令
- 開發 Shell 命令
- adb shell 命令整理
- shell基本命令
- 【SHELL】grep 命令用法
- shell常用的命令
- 強大好用的shell之shell命令
- HBase架構與基礎命令架構
- 理解shell的eval命令
- Shell學習【test命令】
- CMD和power shell命令
- shell簡單命令大全。
- 【SHELL】命令使用筆記筆記
- Shell echo命令介紹
- Linux shell命令總結Linux
- linux Shell 命令列-03-array Shell 陣列Linux命令列陣列
- python裡執行shell命令或cmd命令Python
- 【Mongo】shell命令列模式執行mongo命令Go命令列模式
- Linux基礎命令---enable開啟shell命令Linux
- 常用adb 和 adb shell 命令
- Shell程式設計-read命令程式設計
- shell-----結構化命令
- Power Shell 常用命令
- shell中擴充套件命令套件