HBase 基本操作

1. 基本 增 删 改 查
[root@Node1 bin]# ./hbase shell	 ---# 启动 

hbase(main):001:0> create 'student','info'  ---# 必须要有 '表名', '列簇‘  
hbase(main):002:0> create 'hbase_test',{NAME => 'f1',VERSION => 1}

hbase(main):002:0> list	---# 相当于show tables
TABLE                                                                              
student                                                                            
test                                                                               
2 row(s) in 0.1410 seconds

hbase(main):004:0> desc 'student'	---# 查看表结构
Table student is ENABLED                                                           
student                                                                            
COLUMN FAMILIES DESCRIPTION                                                        
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW',
REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', 
MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', 
BLOCKSIZE => '65536', IN_MEMORY => 'false',BLOCKCACHE => 'true'}                                                             
1 row(s) in 0.8520 seconds

 ---# 插入数据
hbase(main):003:0> put 'student','1001','info:sex','male'
hbase(main):004:0> put 'student','1001','info:age','18'
hbase(main):005:0> put 'student','1001','info:name','Spark'
hbase(main):006:0> put 'student','1002','info:name','Janna'
hbase(main):007:0> put 'student','1002','info:sex','female'
hbase(main):008:0> put 'student','1002','info:age','20'

hbase(main):005:0> scan 'student'	---# 查询数据
ROW                   COLUMN+CELL                                                  
1001                 column=info:age, timestamp=1602493283192, value=18           
1001                 column=info:name, timestamp=1602493313879, value=Spark       
1001                 column=info:sex, timestamp=1602493233141, value=male         
1002                 column=info:age, timestamp=1602493327478, value=20           
1002                 column=info:name, timestamp=1602493292174, value=Janna       
1002                 column=info:sex, timestamp=1602493322683, value=female       
2 row(s) in 1.2800 seconds

hbase(main):008:0> scan 'student',{STARTROW => '1001', STOPROW  => '1001'}
ROW                   COLUMN+CELL                                                  
1001                 column=info:age, timestamp=1602493283192, value=18           
1001                 column=info:name, timestamp=1602493313879, value=Spark       
1001                 column=info:sex, timestamp=1602493233141, value=male         
1 row(s) in 0.1890 seconds

hbase(main):008:0> disable 'test'	---# 关闭表
hbase(main):008:0> drop 'test'		---# 删除表
hbase(main):008:0> enable 'test'		---# 启用表
hbase(main):008:0> truncate 'test'		---# 清空表中数据

hbase(main):010:0> get 'student','1001'	---# get 获取数据
COLUMN                CELL                                                         
info:age             timestamp=1602493283192, value=18                            
info:name            timestamp=1602493313879, value=Spark                         
info:sex             timestamp=1602493233141, value=male                          
3 row(s) in 0.2800 seconds

hbase(main):011:0> get 'student','1001','info:name'
COLUMN                CELL                                                         
info:name            timestamp=1602493313879, value=Spark                         
1 row(s) in 0.1770 seconds

hbase(main):012:0> deleteall 'student','1001'	---# 删除行
hbase(main):013:0> delete 'student','1002','f1:name'	---# 删除列中字段
hbase(main):014:0> put 'student','1002','info:age','24'	---# 更新指定字段的数据
hbase(main):006:0> get 'student','1001','info:age'
COLUMN                CELL                                                         
info:age             timestamp=1602496498996, value=24                            
1 row(s) in 0.1150 seconds

hbase(main):008:0>  alter 'student',{NAME=>'info',VERSIONS=>3}	---# 将info列族中的数据存放3个版本
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 4.8640 seconds

hbase(main):018:0> put 'student','1001','info:age','27'
0 row(s) in 0.0370 seconds

hbase(main):019:0> get 'student','1001',{COLUMN=>'info:age',VERSIONS=>3}
COLUMN                CELL                                                         
info:age             timestamp=1602496931040, value=27                            
info:age             timestamp=1602496498996, value=24                            
2 row(s) in 0.0710 seconds

2. API 操作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值