1.创建表和列族
Create ‘user’,’base_info’,’extal_info’
2.列出所有表
List
3.显示表的详细信息
Describe ‘user’
4.修改表,禁用表,启用表
添加列族 alter ‘user’,‘info1’
Alter ‘user’,{NAME=>’extal_info’,method=>’delete’}
Alter ‘user’,‘info3‘
Enabled ‘user’ disabled ‘user’
5.删除表
Drop ‘user’
6.数据操作
插入数据
用到的表创建语句:
hbase(main):011:0> create 'myns:user_info','base_info','extra_info'
1. 插入数据(put命令,不能一次性插入多条)
hbase(main):012:0> put 'myns:user_info','001','base_info:username','张三'
2. scan扫描
hbase(main):024:0> scan 'myns:user_info'
3. 通过指定版本查询
hbase(main):024:0> scan 'myns:user_info', {RAW => true, VERSIONS => 1}
hbase(main):024:0> scan 'myns:user_info', {RAW => true, VERSIONS => 2}
4. 查询指定列的数据
hbase(main):014:0> scan 'myns:user_info',{COLUMNS => 'base_info:username'}
5. 分页查询
hbase(main):021:0> scan 'myns:user_info', {COLUMNS => ['base_info:username'], LIMIT => 10, STARTROW => '001'}
6. get查询
hbase(main):015:0> get 'myns:user_info','001','base_info:username'
hbase(main):017:0> put 'myns:user_info','001','base_info:love','basketball'
hbase(main):018:0> get 'myns:user_info','001'
7. 根据时间戳查询 是一个范围,包头不包尾
hbase(main):029:0> get 'myns:user_info','001', {'TIMERANGE' => [1571650017702, 1571650614606]}
8. hbase排序
插入到hbase中去的数据,hbase会自动排序存储:
排序规则: 首先看行键,然后看列族名,然后看列(key)名; 按字典顺序
9. 更新数据
hbase(main):010:0> put 'myns:user_info', '001', 'base_info:name', 'rock'
hbase(main):011:0> put 'myns:user_info', '001', 'base_info:name', 'eRRRchou'
10. incr计数器
hbase(main):053:0> incr 'myns:user_info', '002', 'base_info:age3'
11. 删除
hbase(main):058:0> delete 'myns:user_info', '002', 'base_info:age3'
12. 删除一行
hbase(main):028:0> deleteall 'myns:user_info','001'
13. 删除一个版本
hbase(main):081:0> delete 'myns:user_info','001','extra_info:feature', TIMESTAMP=>1546922931075
14. 删除一个表
hbase(main):082:0> disable 'myns:user_info'
hbase(main):083:0> drop 'myns:user_info'
15. 判断表是否存在
hbase(main):084:0> exists 'myns:user_info'
16. 表生效和失效
hbase(main):085:0> enable 'myns:user_info'
hbase(main):086:0> disable 'myns:user_info'
17. 统计表行数
hbase(main):088:0> count 'myns:user_info'
18. 清空表数据
hbase(main):089:0> truncate 'myns:user_info'