1、进入HBase客户端命令行
[root@hadoop102 hbase]$ bin/hbase shell
2、查看帮助命令
hbase(main):001:0> help
3、查看当前数据库中有哪些表
hbase(main):002:0> list
hbase(main):002:0> create 'student','info'
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'
hbase(main):008:0> scan 'student'
hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW => '1001'}
hbase(main):010:0> scan 'student',{STARTROW => '1001'}
hbase(main):011:0> describe ‘student’d
hbase(main):012:0> put 'student','1001','info:name','Nick'
hbase(main):013:0> put 'student','1001','info:age','100'
hbase(main):014:0> get 'student','1001'
hbase(main):015:0> get 'student','1001','info:name'
hbase(main):021:0> count 'student'
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
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>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
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
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
指定了几个版本底层会保存几次最新值,但是获取时返回的一定是最新的版本;
删除某rowkey的全部数据:
hbase(main):016:0> deleteall 'student','1001'
删除某rowkey的某一列数据:
hbase(main):017:0> delete 'student','1002','info:sex'
hbase(main):018:0> truncate 'student'
提示:清空表的操作顺序为先disable,然后再truncate。
首先需要先让该表为disable状态:
hbase(main):019:0> disable 'student'
然后才能drop这个表:
hbase(main):020:0> drop 'student'
提示:如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.