HBase2.1.0表操作命令

首先进入HBase

[root@master ~]# hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 2.1.0, re1673bb0bbfea21d6e5dba73e013b09b8b49b89b, Tue Jul 10 17:26:48 CST 2018
Took 0.0042 seconds                                                                                                                             
hbase(main):001:0>

创建表

语法:

create 't1', {NAME => 'f1'}, {NAME => 'f2'}
create 't1', 'f1', 'f2'
t1表示table,f1~n表示列簇名,一个表建议最多创建不超过5个列簇,否则影响性能。

hbase(main):007:0> create 'table1',{NAME=>'user'},{NAME=>'job'}
Created table table1
Took 1.4312 seconds                                                                                                                             
=> Hbase::Table - table1

hbase(main):008:0> create 'table2','f1','f2'
Created table table2
Took 2.2703 seconds                                                                                                                             
=> Hbase::Table - table2

添加/更新记录

语法:

put 't1','rowkey','family:column','value'

t1表示table,family表示列簇名,column表示列名。

hbase(main):011:0> put 'table1','0001','user:age','25'
Took 0.3098 seconds
hbase(main):013:0> put 'table1','0001','user:name','Jack'
Took 0.0188 seconds

通过scan命令可查看表信息。

hbase(main):014:0> scan 'table1'
ROW                                   COLUMN+CELL                                                                                               
 0001                                 column=user:age, timestamp=1544513083905, value=25                                                        
 0001                                 column=user:name, timestamp=1544513217164, value=Jack                                                     
1 row(s)
Took 0.0115 seconds 

查看表和表信息和表数据存储

hbase(main):009:0> list
TABLE                                                                                                                                           
table1                                                                                                                                          
table2                                                                                                                                          
2 row(s)
Took 0.0338 seconds                                                                                                                             
=> ["table1", "table2"]
hbase(main):014:0> scan 'table1'
ROW                                   COLUMN+CELL                                                                                               
 0001                                 column=user:age, timestamp=1544513083905, value=25                                                        
 0001                                 column=user:name, timestamp=1544513217164, value=Jack                                                     
1 row(s)
Took 0.0115 seconds 

查看对应RowKey的记录。

hbase(main):018:0> get 'table1','0001'
COLUMN                                CELL                                                                                                      
 user:age                             timestamp=1544513083905, value=25                                                                         
 user:name                            timestamp=1544513217164, value=Jack                                                                       
1 row(s)
Took 0.0432 seconds

查看表的详细数据存储信息(第一行可看出table1表是可用状态)

hbase(main):015:0> describe 'table1'
Table table1 is ENABLED                                                                                                                         
table1                                                                                                                                          
COLUMN FAMILIES DESCRIPTION                                                                                                                     
{NAME => 'job', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON
_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_I
NDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLO
CKCACHE => 'true', BLOCKSIZE => '65536'}                                                                                                        
{NAME => 'user', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_O
N_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_
INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BL
OCKCACHE => 'true', BLOCKSIZE => '65536'}                                                                                                       
2 row(s)
Took 0.1192 seconds 

删除表中某行某列记录

语法:

delete 't1','rowkey','family:column'

t1表示table,family表示列簇名,column表示列名。

hbase(main):020:0> delete 'table1','0001','user:age'
Took 0.0365 seconds

查询可见成功删除age列信息。

hbase(main):021:0> get 'table1','0001'
COLUMN                                CELL                                                                                                      
 user:name                            timestamp=1544513217164, value=Jack                                                                       
1 row(s)
Took 0.0198 seconds 

删除整表

hbase(main):032:0> disable 'table2'
Took 0.7826 seconds
hbase(main):034:0> drop 'table2'
Took 0.7971 seconds
enable 'table'      # 激活表
disable 'table'     # 禁用表
is_enabled 'table'  # 查看表是否可用,是则返回true
is_disabled 'table' # 查看表是否可用,是则返回false

其他命令

①计算表的行数

hbase(main):020:0> count 'table1'
2 row(s)
Took 0.0202 seconds                                                                                                                             
=> 2

②初始化表(去除原有的数据,表结构不变)

hbase(main):022:0> truncate 'table2'
Truncating 'table2' table (it may take a while):
Disabling table...
Truncating table...
Took 2.1430 seconds

你可能感兴趣的:(HBase,Hadoop,HBase从搭建到操作)