HBase简单使用
hbase控制台终端操作
启动hbase的shell
$ bin/hbase shell
查看帮助命令
hbase(main)> help
查看当前数据库中有哪些表
hbase(main)> list
表的操作
注意:在hbase shell中退格需要用ctrl+退格键
创建表
-- create '表名,'列族(colum-family)'
ex: hbase> create 'student','info'
插入数据
hbase> put '表名','rowkey','列族名:列名1','值'
ex: hbase> put 'student','1001','info:name','daxiong'
hbase(main) > put 'student','1001','info:name','Thomas'
hbase(main) > put 'student','1001','info:sex','male'
hbase(main) > put 'student','1001','info:age','18'
hbase(main) > put 'student','1002','info:name','Janna'
hbase(main) > put 'student','1002','info:sex','female'
hbase(main) > put 'student','1002','info:age','20'
查看数据
--查看全表
hbase > scan 'student'
-- 查看指定范围
hbase > scan 'student',{STARTROW => '1001',STOPROW => '1002'}
-- 查看指定行
hbase > get 'student','1001'
hbase > get 'student','1001','info'
hbase > get 'student','1001','info:name'
上述操作的区间:前闭后开
查看表结构
hbase(main): describe 'student'
删除数据
--删除某rowkey的全部数据
hbase(main) > deleteall 'student','1001'
--删除某rowkey的全部数据
hbase(main) > deleteall 'student','1001','info:sex'
清空表
hbase(main) > truncate 'student'
清空表的操作顺序为先disable,然后再truncating
删除表
--首先需要先让该表为disable状态
hbase(main) > disable 'student'
--然后才能drop这个表
hbase(main) > drop 'student'
如果直接drop表,会报错:Drop the named table. Tablemust first be disabled
ERROR: Table student is enabled. Disable itfirst.
统计表数据行数
hbase(main) > count 'student'