HBase shell 常用命令

目录

    • 安装 HBase
    • 进入HBase shell
    • 查看当前用户
    • status:hbase集群的状态信息
    • version:hbase版本信息
    • create:创建表
    • list:列出hbase中存在的所有表
    • put:向指向的表单元添加值
    • get:获取行或单元(cell)的值
    • count:通过对表的扫描来获取表的行数
    • scan:通过对表的扫描来获取对应的值
    • describe:显示表相关的详细信息
    • delete:删除指定对象的值(可以为表、行、列对应的值,另外也可以指定时间戳的值)
    • enable:使表有效
    • disable:使表无效
    • drop:删除表(注:删除某个表之前,必须先使该表无效)
    • exists:测试表是否存在
    • exit:退出hbase shell

安装 HBase

https://blog.csdn.net/yitengtongweishi/article/details/81983379

进入HBase shell

blockchain@Dao:~$ hbase-1.4.6/bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/blockchain/hbase-1.4.6/lib/phoenix-4.14.0-HBase-1.4-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/blockchain/hbase-1.4.6/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/blockchain/hadoop-2.6.5/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 1.4.6, ra55bcbd4fc87ff9cd3caaae25277e0cfdbb344a5, Tue Jul 24 16:25:52 PDT 2018

hbase(main):001:0> 

查看当前用户

hbase(main):001:0> whoami
blockchain (auth:SIMPLE)
    groups: blockchain, adm, cdrom, sudo, dip, plugdev, lpadmin, sambashare

hbase(main):002:0> 

status:hbase集群的状态信息

hbase(main):018:0* status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load

hbase(main):019:0> 

version:hbase版本信息

hbase(main):025:0* version
1.4.6, ra55bcbd4fc87ff9cd3caaae25277e0cfdbb344a5, Tue Jul 24 16:25:52 PDT 2018

hbase(main):026:0> 

create:创建表

hbase(main):027:0* create 'tab1', 'cf1'
0 row(s) in 2.6090 seconds

=> Hbase::Table - tab1
hbase(main):028:0> create 'tab2', 'cf1', 'cf2'
0 row(s) in 2.3570 seconds

=> Hbase::Table - tab2
hbase(main):029:0> 

list:列出hbase中存在的所有表

hbase(main):031:0* list
TABLE                                                                                                 
tab1                                                                                                  
tab2                                                                                                  
2 row(s) in 0.0050 seconds

=> ["tab1", "tab2"]
hbase(main):032:0> 

put:向指向的表单元添加值

hbase(main):033:0* put 'tab1', 'row-1', 'cf1:greet', 'Hello'
0 row(s) in 0.0620 seconds

hbase(main):034:0> put 'tab1', 'row-1', 'cf1:pie', 3.14
0 row(s) in 0.0460 seconds

hbase(main):035:0> put 'tab1', 'row-2', 'cf1:pie', 3.14
0 row(s) in 0.0060 seconds

get:获取行或单元(cell)的值

hbase(main):039:0* get 'tab1', 'row-1'
COLUMN                     CELL                                                                       
 cf1:greet                 timestamp=1535459800225, value=Hello                                       
 cf1:pie                   timestamp=1535459813854, value=3.14                                        
1 row(s) in 0.0300 seconds

hbase(main):040:0> 
hbase(main):041:0* get 'tab1', 'row-2'
COLUMN                     CELL                                                                       
 cf1:pie                   timestamp=1535459822153, value=3.14                                        
1 row(s) in 0.0030 seconds

hbase(main):042:0> 

count:通过对表的扫描来获取表的行数

hbase(main):017:0> 
hbase(main):018:0* count 'tab1'
2 row(s) in 0.0030 seconds

=> 2
hbase(main):019:0> 

scan:通过对表的扫描来获取对应的值

hbase(main):044:0* scan 'tab1'
ROW                        COLUMN+CELL                                                                
 row-1                     column=cf1:greet, timestamp=1535459800225, value=Hello                     
 row-1                     column=cf1:pie, timestamp=1535459813854, value=3.14                        
 row-2                     column=cf1:pie, timestamp=1535459822153, value=3.14                        
2 row(s) in 0.0120 seconds

hbase(main):045:0> 

describe:显示表相关的详细信息

hbase(main):046:0* describe 'tab1'
Table tab1 is ENABLED                                                                                 
tab1                                                                                                  
COLUMN FAMILIES DESCRIPTION                                                                           
{NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLO
CKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                    
1 row(s) in 0.0270 seconds

hbase(main):047:0> 

delete:删除指定对象的值(可以为表、行、列对应的值,另外也可以指定时间戳的值)

hbase(main):048:0* delete 'tab1', 'row-1', 'cf1:pie'
0 row(s) in 0.0210 seconds

hbase(main):049:0> scan 'tab1'
ROW                        COLUMN+CELL                                                                
 row-1                     column=cf1:greet, timestamp=1535459800225, value=Hello                     
 row-2                     column=cf1:pie, timestamp=1535459822153, value=3.14                        
2 row(s) in 0.0090 seconds

hbase(main):050:0> 

enable:使表有效

disable:使表无效

drop:删除表(注:删除某个表之前,必须先使该表无效)

hbase(main):053:0> disable 'tab1'
0 row(s) in 2.3870 seconds

hbase(main):054:0> drop 'tab1'
0 row(s) in 1.3190 seconds

hbase(main):055:0> list
TABLE                                                                                                 
tab2                                                                                                  
1 row(s) in 0.0040 seconds

=> ["tab2"]
hbase(main):056:0> 

exists:测试表是否存在

hbase(main):058:0* exists 'tab1'
Table tab1 does not exist                                                                             
0 row(s) in 0.0100 seconds

hbase(main):059:0> exists 'tab2'
Table tab2 does exist                                                                                 
0 row(s) in 0.0030 seconds

hbase(main):060:0> 

exit:退出hbase shell

hbase(main):062:0* exit
blockchain@Dao:~$ 
blockchain@Dao:~$ 

友情链接

你可能感兴趣的:(HBase,Hive,Hadoop,HBase)