二、Hbase客户端shell操作

HBase Shell操作

一、基本操作

1、进入HBase客户端命令行

[root@hadoop102 hbase]$ bin/hbase shell

2、查看帮助命令

hbase(main):001:0> help

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

hbase(main):002:0> list

二、表的相关操作

1.创建表getget
hbase(main):002:0> create 'student','info'
2.插入数据到表
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','1002','info:name','Janna'
hbase(main):006:0> put 'student','1002','info:sex','female'
hbase(main):007:0> put 'student','1002','info:age','20'
3.扫描查看表数据
hbase(main):008:0> scan 'student'
hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW  => '1001'}
hbase(main):010:0> scan 'student',{STARTROW => '1001'}
4.查看表结构
hbase(main):011:0> describe ‘student’d
5.更新指定字段的数据
hbase(main):012:0> put 'student','1001','info:name','Nick'
hbase(main):013:0> put 'student','1001','info:age','100'
6.查看“指定行”或“指定列族:列”的数据
hbase(main):014:0> get 'student','1001'
hbase(main):015:0> get 'student','1001','info:name'
7.统计表数据行数
hbase(main):021:0> count 'student'
8、变更表信息-版本使用

8.1此时只有一条数据
hbase(main):019:0> scan 'student'
ROW        a                           COLUMN+CELL                                                                                                 
 1001                                 column=info:sex, timestamp=1574695433041, value=male                                                        
1 row(s) in 0.0260 seconds
8.2将info列族中的数据存放3个版本:
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
8.3此时只有一条数据,也就是一个版本
hbase(main):021:0> get 'student','1001',{COLUMN=>'info:sex',VERSIONS=>3}
COLUMN                                CELL                                                                                                        
 info:sex                             timestamp=1574695433041, value=male                                                                         
1 row(s) in 0.0360 seconds
8.4修改sex数据,再查询
hbase(main):022:0> put 'student','1001','info:sex','famale'
0 row(s) in 0.0380 seconds

此时有两个版本

hbase(main):023:0> get 'student','1001',{COLUMN=>'info:sex',VERSIONS=>3}
COLUMN                                CELL                                                                                                        
 info:sex                             timestamp=1574695681028, value=famale                                                                       
 info:sex                             timestamp=1574695433041, value=male                                                                         
1 row(s) in 0.0120 seconds
8.5多修改几次看看底层会保存几次版本,并且scan时数据是什么值
hbase(main):024:0> put 'student','1001','info:sex','famale111'
0 row(s) in 0.0290 seconds

hbase(main):025:0> put 'student','1001','info:sex','famale222'
0 row(s) in 0.0200 seconds

此时保存的版本中已经没有了male值,也就是指定了3个版本,底层只保留最新的三个值

hbase(main):026:0> get 'student','1001',{COLUMN=>'info:sex',VERSIONS=>3}
COLUMN                                CELL                                                                                                        
 info:sex                             timestamp=1574695762316, value=famale222                                                                    
 info:sex                             timestamp=1574695754743, value=famale111                                                                    
 info:sex                             timestamp=1574695681028, value=famale                                                                       
1 row(s) in 0.0230 seconds

查询返回最新的

hbase(main):027:0> scan 'student'
ROW                                   COLUMN+CELL                                                                                                 
 1001                                 column=info:sex, timestamp=1574695762316, value=famale222                                                   
1 row(s) in 0.0370 seconds

指定了几个版本底层会保存几次最新值,但是获取时返回的一定是最新的版本;

9、删除数据

删除某rowkey的全部数据:

hbase(main):016:0> deleteall 'student','1001'

删除某rowkey的某一列数据:

hbase(main):017:0> delete 'student','1002','info:sex'
10、清空表数据
hbase(main):018:0> truncate 'student'

提示:清空表的操作顺序为先disable,然后再truncate。

11、删除表

首先需要先让该表为disable状态:

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

然后才能drop这个表:

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

提示:如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值