[root@slave1 local]#hbase shell #进入HBase客户端命令行
hbase(main):024:0> list [列出HBase的所有表]
[创建表]
# 创建表t1,有两个family name:f1,f2,且版本数均为2
create 't1',{NAME => 'f1', VERSIONS => 2},{NAME => 'f2', VERSIONS => 2}
create 'test','cf' [test为表名,cf为列族]
create 'test1','cf1','cf2'
create 'student','info'
[查看表结构]
echo "describe 'student'"|hbase shell
describe 'student'
[插入数据到表]
hbase(main):003:0> put 'student','1001','info:sex','male'
hbase(main):004:0> put 'student','1001','info:age','18'
hbase(main):005:0> put 'student','1002','info:name','Janna'
hbase(main):006:0> put 'student','1002','info:sex','female'
hbase(main):007:0> put 'student','1002','info:age','20'
[扫描查看表数据]
hbase(main):008:0> scan 'student'
hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW => '1001'}
hbase(main):010:0> scan 'student',{STARTROW => '1001'}
hbase(main):201:0> scan 'student',{STARTROW=>'1',LIMIT=>1}
hbase(main):124:0> scan 'student',{LIMIT=>2} #扫描表student的前5条数据
[更新指定字段的数据]
hbase(main):012:0> put 'student','1001','info:name','Nick'
hbase(main):013:0> put 'student','1001','info:age','100'
[查看[指定行”或“指定列族:列]的数据]
echo "get 'boye:test','10001','info:name'"|hbase shell
hbase(main):014:0> get 'student','1001'
hbase(main):015:0> get 'student','1001','info:name'
hbase(main):080:0> get 'student','1001','info:age','info:sex'
[删除数据]
hbase(main):016:0> deleteall 'student','1001' #删除某rowkey的全部数据
hbase(main):017:0> delete 'student','1002','info:sex' #删除某rowkey的某一列数据
[删除表]
分两步:首先disable,然后drop
hbase(main):019:0> disable 'student'
hbase(main):020:0> drop 'student'
[清空表数据]
hbase(main):018:0> truncate 'student'
提示:清空表的操作顺序为先disable,然后再truncate
[变更表信息]
将info列族中的数据存放3个版本:
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
hbase(main):132:0> get 'student','1001',{COLUMN=>'info:name',VERSIONS=>1}
[命名空间]
hbase(main):132:0> list_namespace #查看命名空间
hbase(main):132:0> create_namespace 'boye' #创建命名空间
hbase(main):132:0> create 'boye:test','info','detail' #指定命名空间创建表