HBase | 基本使用
HBase Shell操作
- 基本操作
- 进入HBase客户端
bin/hbase shell
- 查看帮助
help
- 查看当前数据库中有哪些表
list
- 进入HBase客户端
- 表的操作
- 创建表
create 'student','info'
格式 create '表名','列族' - 插入数据到表
#格式 请求方式 '表名','行名','列族:列','值' 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'
- 创建表
- 扫描查看表数据
scan 'student'
scan 'student',{STARTROW => '1001', STOPROW =>'1001'}
scan 'student',{STARTROW => '1001'}
- 查看表结构
describe 'student'
- 更新指定字段数据
put 'student','1001','info:name','Nick' put 'student','1001','info:age','100'
- 查看“指定行”或“指定列族:列”的数据
+get 'student','1001'
+get 'student','1001','info:name'
- 统计表数据行数
count 'student'
- 删除
某 rowkey
数据deleteall 'student','1001'
- 删除
某 rowkey
的某一列数据:delete 'student','1002','info:sex'
- 清空表数据
truncate 'student'
提示:清空表的操作顺序为先 disable,然后再 truncate。
- 删除表
- 先让表处于
disable
状态disable 'student'
- 然后
drop
这个表drop 'student'
- 先让表处于
如果直接
drop
表 会报错ERROR: Table student is enabled. Disable it first.
- 变更表信息
- 将info列族的数据存放3个版本
alter 'student',{NAME=>'info',VERSIONS=>3} get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}