HBase Shell入门操作

在启动HBase服务前,确保hadoop和zookeeper都已经启动

HBase Shell入门操作

在进入HBase Shell操作前
启动HBase服务


bin/start-hbase.sh

HBase Shell入门操作

对应的停止服务 在停止zookeeper之前停止hbase,否则hbase会出现无法停止的状况


bin/stop-hbase.sh


进入HBase客户端命令行


bin/hbase shell

HBase Shell入门操作

查看当前数据库中有哪些表
list 新安装的HBase内是没有表的

HBase Shell入门操作

针对表的操作

1.创建表

create 'test','f1','f2'
test为表名,f1,f2为列族,列族可以有多个

HBase Shell入门操作

2.插入及更新数据到表

put 'test','1001','f1:name','zhangsan'
put 'test','1001','f1:age','18'
put 'test','1002','f1:name','2zhangsan'
put 'test','1002','f1:age','28'
put 'test','1003','f1:name','3zhangsan'
put 'test','1003','f1:age','38'
put为插入及修改关键字 test是表名,1001为行键,f1:name为列族:列名 zhangsan为值

3.查看表数据

scan 'test'
如果表中数据较多,不建议scan全表
scan 'test',{STARTROW=>'1001',STOPROW=>'1001'}
开始行号,结束行号,左闭右开,也就是俗称的含头不含尾
scan 'test',{STARTROW => '1001'}
STARTROW也可以单独使用

HBase Shell入门操作

4.查看表结构

desc 'test'

5.查看指定行或指定列族:列的数据

get 'test','1001'
get 'test','1001','f1:name'

HBase Shell入门操作

6.删除数据

delete 'test','1001','f1:name'
删除1001行中 info列族内 列名为name的数据
deleteall 'test','1001'
删除整个一行

deleteall 'test','1001' 前

HBase Shell入门操作

deleteall 'test','1001' 后

HBase Shell入门操作

7.清空数据表

truncate 'test'
清空表的操作顺序为先disable,然后再truncate

清空前

HBase Shell入门操作

清空后

HBase Shell入门操作

8.删除表

首先需要先让该表为disable状态,然后才能drop这个表
disable 'test'
drop 'test'
如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first