iiwen

新增

//语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
//新增或者覆盖数据 put \'表名\',\'键名\',\'列名(不是列簇名)\',\'值\'
//指定的列名下单元格有值就覆盖..没有值就创建.所以HBase的添加数据和修改数据都是put语句..
//最后的时间戳可以不写..默认为系统时间,如果要写..切记不可使用引号括起来

hbase shell> put \'mytable\',\'woshikey\',\'ct:msg\',\'99999999999999\'
hbase shell> put \'mytable\',\'woshikey\',\'ct:msg\',\'99999999999999\',1462241148

 

删除 

//删除某个单元值的值  会删除所有版本
//语法:delete <table>, <rowkey>,  <family:column> , <timestamp>,必须指定列名
//测试后发现后边跟时间戳也没有用,依然会删除所有版本
hbase shell> delete \'mytable\',\'rowkey\',\'ct:msg\'

//删除行或者整个列簇
//语法:deleteall <table>, <rowkey>,  <family:column> , <timestamp>,可以不指定列名,删除整行数据
hbase shell> deleteall \'mytable\',\'ct\'
hbase shell> deleteall \'mytable\'

//清空表数据
//语法: truncate <table>
//等同于 disable -> drop -> create
hbase shell> truncate \'mytable\'

查询   

//扫描表
//语法: scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
hbase shell> scan \'mytable\'
hbase shell> scan \'mytable\',{COLUMNS=>\'ct\'}
hbase shell> scan \'mytable\',{COLUMNS=>\'ct\',LIMIT=>1}  //返回所属列簇里每个列的第一个值 
hbase shell> scan \'mytable\',{COLUMNS=>\'ct:msg\',LIMIT=>1}

//获取表数据
//语法: get <table>,<key>[,<columns>]
hbase shell> get \'mytable\',\'rowkey1\'
hbase shell> get \'mytable\',\'rowkey1\',\'ct\'
hbase shell> get \'mytable\',\'rowkey1\',\'ct:msg\'
hbase shell> get \'mytable\',\'rowkey1\',{COLUMN=>\'ct\'}
hbase shell> get \'mytable\',\'rowkey1\',{COLUMN=>\'ct:msg\'}

//获取表行数
//语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
//INTERVAL设置多少行显示一次及对应的rowkey,默认1000;CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
//例如,查询表t1中的行数,每100条显示一次,缓存区为500 
hbase shell> count \'mytable\', {INTERVAL => 100, CACHE => 500}

 

分类:

技术点:

相关文章: