HBase基本shell命令

以下shell命令都是经过测试,正常展示,若有不足,还望指点!

1、创建表 create ‘表名称’,‘列族名称1’,‘列族名称1’
create 'test_M_01','test_id','address','info'

2、全表扫描 scan '表名'
scan 'test_M_01'

3、获得表的描述 describe '表名'
describe 'test_M_01'

4、向表中插入数据或更新数据 put
put 'test_M_01','row1','info:name','mmj'
put 'test_M_01','row1','info:age','19'
put 'test_M_01','row1','address:qq','123@qq.com'

put 'test_M_01','row2','info:age','20'
put 'test_M_01','row2','address:qq','3234234234@qq.com'

5、根据行获取数据
get 'test_M_01','row1' #根据行名称,获取一条数据。
get 'test_M_01','row1','info' #根据行名称,列族名称获取一条数据。

6、根据时间戳来获取数据
get 'test_M_01','row1',{COLUMN=>'info:age',TIMESTAMP=>1402307446697}

7、查询表中有多少行 count '表名'
count 'test_M_01'

8、删除
delete 'test_M_01','row1','info:age' #删除id为row1的info:age字段
deleteall 'test_M_01','row1' #删除id为row1的一整行

9、清空整张表 truncate 'test_M_01'
hbase(main):007:0> truncate 'test_M_01'
Truncating 'test_M_01' table (it may take a while):
- Disabling table...
- Dropping table...
- Creating table...
0 row(s) in 4.4410 seconds

第九条命令的结果说明,HBase的清空表的操作的步骤是:第一步,将表标志为Disabled,第二步,删除该表,第三步,重新创建表。

04-28 04:43