HBase(2)- HBase Shell

1 基本操作
进入HBase客户端命令行

[hadoop@hadoop101 hbase]$ bin/hbase shell

查看帮助命令

hbase(main):001:0> help

查看当前数据库中有哪些表

hbase(main):002:0> list

2 表的操作
创建表

hbase(main):003:0> create 'student','info'

插入数据到表

hbase(main):005:0> put 'student','100001','info:name','jack'
hbase(main):006:0> put 'student','100001','info:sex','male'
hbase(main):007:0> put 'student','100001','info:age','25'
hbase(main):008:0> put 'student','100001','info:name','tommy'
hbase(main):009:0> put 'student','100001','info:age','27'
hbase(main):010:0> put 'student','100001','info:name','jenney'
hbase(main):011:0> put 'student','100001','info:sex','female'
hbase(main):012:0> put 'student','100001','info:age','28'

扫描查看表数据

hbase(main):013:0> scan 'student'
ROW                          COLUMN+CELL                                                                      
 100001                      column=info:age, timestamp=1638593700908, value=28                               
 100001                      column=info:name, timestamp=1638593686889, value=jenney                          
 100001                      column=info:sex, timestamp=1638593695515, value=female                           
1 row(s) in 0.0130 seconds

向不同的rowkey插入数据

hbase(main):014:0> put 'student','100002,'info:name','jack'
hbase(main):015:0' put 'student','100002','info:sex','male'
hbase(main):016:0' put 'student','100002','info:age','25'
hbase(main):017:0' put 'student','100003','info:name','tommy'
hbase(main):018:0' put 'student','100003','info:age','27'

扫描查看表数据

hbase(main):019:0> scan 'student'
ROW                          COLUMN+CELL                                                                      
 100001                      column=info:age, timestamp=1638593700908, value=28                               
 100001                      column=info:name, timestamp=1638593686889, value=jenney                          
 100001                      column=info:sex, timestamp=1638593695515, value=female                           
 100002                      column=info:age, timestamp=1638594127776, value=25                               
 100002                      column=info:name, timestamp=1638594106421, value=jack                            
 100002                      column=info:sex, timestamp=1638594120971, value=male                             
 100003                      column=info:age, timestamp=1638594139562, value=27                               
 100003                      column=info:name, timestamp=1638594133113, value=tommy                           
3 row(s) in 0.0200 seconds

STARTROW,STOPROW的查新结果前闭后开

hbase(main):020:0* scan 'student',{STARTROW=>'100001',STOPROW=>'100003'}
ROW                          COLUMN+CELL                                                                      
 100001                      column=info:age, timestamp=1638593700908, value=28                               
 100001                      column=info:name, timestamp=1638593686889, value=jenney                          
 100001                      column=info:sex, timestamp=1638593695515, value=female                           
 100002                      column=info:age, timestamp=1638594127776, value=25                               
 100002                      column=info:name, timestamp=1638594106421, value=jack                            
 100002                      column=info:sex, timestamp=1638594120971, value=male                             
2 row(s) in 0.0190 seconds
hbase(main):021:0> scan 'student',{STARTROW=>'100001'}
ROW                          COLUMN+CELL                                                                      
 100001                      column=info:age, timestamp=1638593700908, value=28                               
 100001                      column=info:name, timestamp=1638593686889, value=jenney                          
 100001                      column=info:sex, timestamp=1638593695515, value=female                           
 100002                      column=info:age, timestamp=1638594127776, value=25                               
 100002                      column=info:name, timestamp=1638594106421, value=jack                            
 100002                      column=info:sex, timestamp=1638594120971, value=male                             
 100003                      column=info:age, timestamp=1638594139562, value=27                               
 100003                      column=info:name, timestamp=1638594133113, value=tommy                           
3 row(s) in 0.0080 seconds

查看表结构

hbase(main):022:0> describe 'student'
Table student is ENABLED                                                                                      
student                                                                                                       
COLUMN FAMILIES DESCRIPTION                                                                                   
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'tru
e', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                           
1 row(s) in 0.0670 seconds

更新指定字段的数据

hbase(main):023:0> put 'student','100001','info:name','Tom'
0 row(s) in 0.0090 seconds

hbase(main):024:0> put 'student','100001','info:age','23'
0 row(s) in 0.0090 seconds

查看“指定行”或“指定列族:列”的数据

hbase(main):025:0> get 'student','100001'
COLUMN                       CELL                                                                             
 info:age                    timestamp=1638594495086, value=23                                                
 info:name                   timestamp=1638594483504, value=Tom                                               
 info:sex                    timestamp=1638593695515, value=female                                            
1 row(s) in 0.0170 seconds

hbase(main):026:0> get 'student','100001','info:name'
COLUMN                       CELL                                                                             
 info:name                   timestamp=1638594483504, value=Tom                                               
1 row(s) in 0.0080 seconds

统计表数据行数

hbase(main):027:0> count 'student'
3 row(s) in 0.0130 seconds

=> 3

删除数据
删除某rowkey的全部数据:

hbase(main):028:0> deleteall 'student','100001'

hbase(main):029:0> scan 'student'
ROW                          COLUMN+CELL                                                                      
 100002                      column=info:age, timestamp=1638594127776, value=25                               
 100002                      column=info:name, timestamp=1638594106421, value=jack                            
 100002                      column=info:sex, timestamp=1638594120971, value=male                             
 100003                      column=info:age, timestamp=1638594139562, value=27                               
 100003                      column=info:name, timestamp=1638594133113, value=tommy                           
2 row(s) in 0.0130 seconds

删除某rowkey的某一列数据:

hbase(main):030:0> delete 'student','100002','info:sex'
0 row(s) in 0.0130 seconds

hbase(main):031:0> scan 'student'
ROW                          COLUMN+CELL                                                                      
 100002                      column=info:age, timestamp=1638594127776, value=25                               
 100002                      column=info:name, timestamp=1638594106421, value=jack                            
 100003                      column=info:age, timestamp=1638594139562, value=27                               
 100003                      column=info:name, timestamp=1638594133113, value=tommy                           
2 row(s) in 0.0070 seconds

清空表数据

hbase(main):032:0> truncate 'student'
Truncating 'student' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 3.4050 seconds

提示:清空表的操作顺序为先disable,然后再truncate。
删除表
首先需要先让该表为disable状态:

hbase(main):034:0> disable 'student'

然后才能drop这个表:

hbase(main):035:0> drop 'student'

提示:如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.
变更表信息
先创建表student并插入以下数据

put 'student','100001','info:name','jack'
put 'student','100001','info:sex','male'
put 'student','100001','info:age','25'
put 'student','100002','info:name','tommy'
put 'student','100002','info:age','27'
put 'student','100003','info:name','jenney'
put 'student','100003','info:sex','female'
put 'student','100003','info:age','28'

将info列族中的数据存放3个版本:

hbase(main):004:0> alter 'student',{NAME=>'info',VERSIONS=>3}

往rowkey '100001' 多次put数据

put 'student','100001','info:name','jack'
put 'student','100001','info:name','tom'
put 'student','100001','info:name','fanny'
put 'student','100001','info:name','lucy'
put 'student','100001','info:name','catey'
put 'student','100001','info:name','jessy'
put 'student','100001','info:name','katey'

将info列族中的数据存放3个版本:

hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
hbase(main):022:0> get 'student','100001',{COLUMN=>'info:name',VERSIONS=>3}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值