Hbase shell 常见操作

Hbase Shell常用操作:
1. 创建表
create '表名', '列族名1','列族名2' 




create 'testorder', 'info','orders'


2. 查看表 
查看所有表列表:list
查看某个表的信息: desc '表名' 或者 describe '表名'
查看表是否存在: exists '表名'


3. 插入数据
put  '表名', 'rowkey值', '列族: 列名' ,'值' 




put 'testorder','00001','info:name','xiao1' 
put 'testorder','00001','info:age','22' 
put 'testorder','00001','info:sex','男' 
put 'testorder','00001','orders:orderid','02018010022' 
 
put 'testorder','00001','orders:price','21' 




put 'testorder','00002','info:name','xiao2' 
put 'testorder','00002','info:age','34' 
put 'testorder','00002','info:sex','女' 
put 'testorder','00002','orders:orderid','02018010055' 
put 'testorder','00002','orders:price','45' 






put 'testorder','00003','info:name','xiao3' 
put 'testorder','00003','info:age','25' 
put 'testorder','00003','info:sex','男' 
put 'testorder','00003','orders:orderid','02018010088' 
put 'testorder','00003','orders:price','27' 


4. 获取表数据


获取单条记录:get '表名','rowkey值'  或者 get '表名','rowkey值','列族名'
扫描全表: scan '表名'  或者  scan '表名' , {COLUMNS=>'列族名'} 或者 scan '表
名' , {COLUMNS=>'列族名:列名'}
scan 'testorder',{COLUMNS=>'info:age'} 


5. 删除表数据
删除列: delete  '表名' ,'行名' , '列族:列'
删除整个行: deleteall '表名','rowkey'
清空表数据: truncate '表名'


6. 删除表
删除表之前需要禁用表。
disable '表名'
drop '表名'


7. 过滤
查看列的值为22:
scan 'testorder',FILTER=>"ValueFilter(=,'binary:22')" 


查看列的值包含xiao:
scan 'testorder',FILTER=>"ValueFilter(=,'substring:xiao')"  
列名以age开头, 且age为22或者25的记录:
scan 'testorder', FILTER=>"ColumnPrefixFilter('ag')  AND (ValueFilter(=,'binary:22') OR
ValueFilter(=,'binary:25') )" 

猜你喜欢

转载自blog.csdn.net/wjl7813/article/details/79951173