(1) 建立一个表格scores 具有两个列族grad 和courese
hbase(main):001:0> create 'scores','grade', 'course'
0 row(s) in 0.4780 seconds
(2) 查看当前HBase中具有哪些表
hbase(main):002:0> list
TABLE
scores
1 row(s) in 0.0270 seconds
(3) 查看表的构造
hbase(main):004:0> describe 'scores'
DESCRIPTION ENABLED
{NAME => 'scores', FAMILIES => [{NAME => 'course', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', true
COMPRESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'fal
se', BLOCKCACHE => 'true'}, {NAME => 'grade', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPR
ESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY =>'false',
BLOCKCACHE =>'true'}]}
1 row(s) in 0.0390 seconds
(4) 加入一行数据,行名称为zkb 列族grad的列名为”” 值位5
hbase(main):006:0> put 'scores','zkb','grade:','5'
0 row(s) in 0.0420 seconds
(5) 给zkb这一行的数据的列族course添加一列<math,97>
hbase(main):007:0> put 'scores','zkb','course:math','97'
0 row(s) in 0.0270 seconds
(6) 给zkb这一行的数据的列族course添加一列<art,87>
hbase(main):008:0> put 'scores','zkb','course:art','87'
0 row(s) in 0.0260 seconds
(7) 加入一行数据,行名称为baoniu 列族grad的列名为”” 值为4
hbase(main):009:0> put 'scores','baoniu','grade:','4'
0 row(s) in 0.0260 seconds
(8) 给baoniu这一行的数据的列族course添加一列<math,89>
hbase(main):010:0> put 'scores','baoniu','course:math','89'
0 row(s) in 0.0270 seconds
(9) 给Jerry这一行的数据的列族course添加一列<art,80>
hbase(main):011:0> put 'scores','baoniu','course:art','80'
0 row(s) in 0.0270 seconds
(10) 查看scores表中zkb的相关数据
hbase(main):012:0> get 'scores','zkb'
COLUMN CELL
course:art timestamp=1316100110921, value=87
course:math timestamp=1316100025944, value=97
grade: timestamp=1316099975625, value=5
3 row(s) in 0.0480 seconds
(11) 查看scores表中所有数据
注意:scan命令可以指定startrow,stoprow来scan多个row,例如:scan 'user_test',{COLUMNS =>'info:username',LIMIT =>10, STARTROW => 'test',STOPROW=>'test2'}
hbase(main):013:0> scan 'scores'
ROW COLUMN+CELL
baoniu column=course:art, timestamp=1316100293784, value=80
baoniu column=course:math, timestamp=1316100234410, value=89
baoniu column=grade:, timestamp=1316100178609, value=4
zkb column=course:art, timestamp=1316100110921, value=87
zkb column=course:math, timestamp=1316100025944, value=97
zkb column=grade:, timestamp=1316099975625, value=5
2 row(s) in 0.0470 seconds
(12) 查看scores表中所有数据courses列族的所有数据
hbase(main):017:0> scan 'scores',{COLUMNS => 'course'}
ROW COLUMN+CELL
baoniu column=course:art, timestamp=1316100293784, value=80
baoniu column=course:math, timestamp=1316100234410, value=89
zkb column=course:art, timestamp=1316100110921, value=87
zkb column=course:math, timestamp=1316100025944, value=97
2 row(s) in 0.0350 seconds
(13) 删除scores表
hbase(main):024:0> disable 'scores'
0 row(s) in 0.0330 seconds
hbase(main):025:0> drop 'scores'
0 row(s) in 1.0840 seconds
(14)清空表数据
hbase(main):025:0>truncate 'scores'
总结下,hbase shell常用的操作命令有create,describe,disable,drop,list,scan,put,get,delete,deleteall,count,status等,通过help可以看到详细的用法。
Hbase shell 的命令
最新推荐文章于 2024-06-30 00:15:00 发布