查看hbase集群状态
status
查看hbase版本
version
hbase namespace
查看所有的namespace
list_namespace
查看某个namespace的详情
describe_namespace 'xxx'
创建namespace
create_namespace 'xxx'
修改namespace的属性
不能修改namespace名,只能修改属性
# set 为新增和修改
alter_namespace 'xxx' , {METHOD=>'set' , 'author'=>'xxx', 'version'=>'xxx' }
# unset 为删除
alter_namespace 'xxx' , {METHOD=>'unset' , NAME=>'version'}
删除namespace,只能删除空的namespace(不能有表)
drop_namespace 'xxx'
hbase table
查看所有的表 list
list
正则查看表
list 'test:ods_cccc_.*'
列出某个namespace下的所有的表
list_namespace_tables 'xxx'
查看表的详情 desc
desc 'xxx'
判断表是否存在 exists
exists 'xxx'
创建表
# 在命名空间 test 下,创建stu表,指定2个列族 base_info、other_info
create_namespace 'test'
create 'test:stu','base_info','other_info'
create as
clone_table_schema 'test:stu' ,'test:new_stu'
修改表结构 alter
# 新增列族cf
alter 'test:stu' , NAME=>'cf'
# 修改列族cf的版本数
alter 'test:stu' , NAME=>'cf' , VERSIONS=>5
# 删除列族cf
alter 'test:stu' , 'delete'=>'cf'
删除表 disable、drop
# 1. 先disable
disable '库名:表名'
# 2. 后drop
drop '库名:表名'
Phoenix删除表:
drop table 库名.表名;
hbase select
查询数据 get
查询一行数据
get 'test:stu' , 'rowkey001'
查询一行数据中的某个单元格
get 'test:stu' , 'rowkey001' ,'other_info:job'
查询数据 scan
scan 'test:stu'
scan 'test:stu' , {STARTROW => 'rowkey001' , STOPROW=>'rowkey001'}
修改数据、插入数据 put
数据存在时,就修改,不存在,插入数据
put 'test:stu' , 'rowkey001' , 'base_info:name', 'zhangxiaosan'
删除数据 delete、deleteall
1、删除指定版本的数据, 如果不指定版本,默认删除最新版本
2、只能删除一行数据的某个单元格
delete 'test:stu' , 'rowkey001' , 'base_info:age'
删除一行数据
deleteall 'test:stu' ,'rowkey001'
turncate
清空表数据 , 直接删除数据文件
truncate 'stu'
统计表中有几行数据 count
统计表中有几行数据
hbase region
建表时,预分region
create 'test:tb_regions', 'cf', SPLITS =>['c','x']
以上分为3个region
a~c、c~x、x~z
列出表的所有 region
列出表tb_regions的所有region
根据 rowkey 定位 region
hbase 表快照 snapshot
现在表中只有一行数据,且只有name和age字段
打快照
snapshot 'test:stu' ,'snapshot_status_1'
恢复快照
# 插入一条数据
put 'test:stu','rowkey001','base_info:gender','M'
# 查询数据
# 禁用表
disable 'test:stu'
# 从快照snapshot_status_1中进行查询
restore_snapshot 'snapshot_status_1'
scan 'test:stu'