hbase shell命令整理

在 HBase 的 HMaster 主机上通过命令行输入 hbase shell,即可进入 HBase 命令行环境
使用status命令查看当前集群各节点的状态
hbase(main):019:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
Took 0.2543 seconds
使用version命令查看当前 HBase 的版本号
hbase(main):020:0> version
2.1.2, r1dfc418f77801fbfb59a125756891b9100c1fc6d, Sun Dec 30 21:45:09 PST 2018

HBase 使用 creat 命令来创建表,创建表时需要指明表名和列族名,这里VERSIONS表示该列族可以保留3个版本
create 'student', {NAME => 'info', VERSIONS => 3}

执行list查看存在哪些表:
hbase(main):022:0> list
TABLE
student
1 row(s)
Took 0.0111 seconds
=> ["student"]

插入数据到表
put 'student','1001','info:name', 'William'
put 'student','1001','info:sex','male'
put 'student','1001','info:age','18'

put 'student','1002','info:name', 'Janna'
put 'student','1002','info:sex','female'
put 'student','1002','info:age','20'

put 'student','1003','info:name', 'Tbag'
put 'student','1003','info:sex','male'
put 'student','1003','info:age','26'

扫描查看表数据
scan 'student'
scan 'student',{STARTROW => '1001', STOPROW => '1001'}
scan 'student',{STARTROW => '1001'}

hbase(main):007:0> scan 'student'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1633508555800, value=18
1001 column=info:name, timestamp=1633508542457, value=William
1001 column=info:sex, timestamp=1633508548751, value=male
1002 column=info:age, timestamp=1633508576783, value=20
1002 column=info:name, timestamp=1633508563895, value=Janna
1002 column=info:sex, timestamp=1633508570629, value=female
2 row(s)
Took 0.1016 seconds

修改已存在的数据某字段的数值
put 'student','1001','info:name','Nick'

对表student添加一个新的列族score
alter 'student','score'
删除表student的一个列族score
alter 'student',{NAME=>'score',METHOD=>'delete'}

查看有多少行
count 'student'

2 row(s)
Took 0.0640 seconds
=> 2

获取多个版本的数据
put 'student','1005','info:name', 'John'
put 'student','1005','info:sex','male'
put 'student','1005','info:age','18'

put 'student','1005','info:name', 'John2'
put 'student','1005','info:name', 'John3'

get 'student','1005',{COLUMN=>'info:name',VERSIONS=>3}

COLUMN CELL
info:name timestamp=1633534128324, value=John3
info:name timestamp=1633534122562, value=John2
info:name timestamp=1633534098576, value=John
1 row(s)
Took 0.0222 seconds

 

删除某rowkey的全部数据

deleteall 'student','1003'
删除某rowkey的某列族的一列数据,下面是删除1002 rowkey的info列族的sex这一列的数据
delete 'student','1003','info:sex'

清空表
truncate 'student'
删除表
disable 'student'
drop 'student'

posted @ 2021-10-06 16:48  tochenwei  阅读(259)  评论(0编辑  收藏  举报