HBase Shell命令使用(0.98) 2015-04-08 22:00

使用

  • 查询服务器状态
hbase(main):001:0> status
2 servers, 0 dead, 2.0000 average load

hbase(main):002:0>

DDL

  • 列出有哪一些表
hbase(main):002:0> list
TABLE
SYSTEM.CATALOG
user
2 row(s) in 0.0550 seconds

=> ["SYSTEM.CATALOG", "user"]
hbase(main):003:0>
  • 查看表结构
hbase(main):007:0> describe 'user'
Table user is ENABLED
user
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE =>
 '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_
DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'
}
{NAME => 'score', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE =
> '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP
_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true
'}
2 row(s) in 0.0510 seconds

hbase(main):008:0>
  • 创建表

创建表user,有两个列族,分别是info和score。

hbase(main):006:0> create 'user','info','score'
0 row(s) in 0.8190 seconds

=> Hbase::Table - user
hbase(main):007:0>
  • 删除表

先disable表,才能删除表。

hbase(main):004:0> disable 'user'
0 row(s) in 1.3660 seconds

hbase(main):005:0> drop 'user'
0 row(s) in 0.4730 seconds

hbase(main):006:0>
  • 检查表是否存在
hbase(main):031:0> exists 'user'
Table user does exist
0 row(s) in 0.0320 seconds

hbase(main):032:0> exists 'house'
Table house does not exist
0 row(s) in 0.0290 seconds

hbase(main):033:0>
  • 判断表是否enable
hbase(main):033:0> is_enabled 'user'
true
0 row(s) in 0.0320 seconds

hbase(main):034:0>

DML

  • 插入数据

插入第一个用户的数据:

hbase(main):008:0> put 'user','0001','info:name','cheyo'
0 row(s) in 0.2870 seconds

hbase(main):009:0> put 'user','0001','info:address','shenzhen'
0 row(s) in 0.0090 seconds

hbase(main):010:0> put 'user','0001','score:english','97'
0 row(s) in 0.0130 seconds

hbase(main):011:0> put 'user','0001','score:chinese','95'
0 row(s) in 0.0110 seconds

hbase(main):022:0>

插入第二个用户的数据:

hbase(main):018:0> put 'user','0002','info:name','rocky'
0 row(s) in 0.0100 seconds

hbase(main):019:0> put 'user','0002','info:address','Xiamen'
0 row(s) in 0.0110 seconds

hbase(main):020:0> put 'user','0002','score:english','98'
0 row(s) in 0.0090 seconds

hbase(main):021:0> put 'user','0002','score:chinese','92'
0 row(s) in 0.0090 seconds

hbase(main):022:0>
  • 更新数据

将user 0002的中文成绩改为99.

hbase(main):036:0> put 'user','0002','score:chinese','99'
0 row(s) in 0.0090 seconds
  • 删除数据

删除记录中的某一个列值

hbase(main):081:0> delete 'user','0002','score:chinese'
0 row(s) in 0.0370 seconds

删除某一条记录

//待补充
  • 清空表
hbase(main):107:0> truncate 'user'
Truncating 'user' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 1.6100 seconds

hbase(main):108:0> scan 'user'
ROW                     COLUMN+CELL
0 row(s) in 0.3250 seconds

hbase(main):109:0>
  • 查看数据
hbase(main):012:0> get 'user','0001'
COLUMN                  CELL
 info:address           timestamp=1428502504741, value=shenzhen
 info:name              timestamp=1428502495509, value=cheyo
 score:chinese          timestamp=1428502529395, value=95
 score:english          timestamp=1428502519927, value=97
4 row(s) in 0.0480 seconds

hbase(main):015:0> get 'user','0001',{COLUMN => 'info'}
COLUMN                  CELL
 info:address           timestamp=1428502504741, value=shenzhen
 info:name              timestamp=1428502495509, value=cheyo
2 row(s) in 0.0190 seconds

hbase(main):016:0> get 'user','0001',{COLUMN => 'score'}
COLUMN                  CELL
 score:chinese          timestamp=1428502529395, value=95
 score:english          timestamp=1428502519927, value=97
2 row(s) in 0.0090 seconds

hbase(main):017:0>
  • 查看表的所有数据
hbase(main):022:0> scan 'user'
ROW                     COLUMN+CELL
 0001                   column=info:address, timestamp=1428502504741, value=shenzhen
 0001                   column=info:name, timestamp=1428502495509, value=cheyo
 0001                   column=score:chinese, timestamp=1428502529395, value=95
 0001                   column=score:english, timestamp=1428502519927, value=97
 0002                   column=info:address, timestamp=1428502755349, value=Xiamen
 0002                   column=info:name, timestamp=1428502736564, value=rocky
 0002                   column=score:chinese, timestamp=1428502776572, value=92
 0002                   column=score:english, timestamp=1428502765774, value=98
2 row(s) in 0.0420 seconds

hbase(main):023:0>

只查看指定的列族:

hbase(main):023:0> scan 'user',{COLUMN=>'info'}
ROW                     COLUMN+CELL
 0001                   column=info:address, timestamp=1428502504741, value=shenzhen
 0001                   column=info:name, timestamp=1428502495509, value=cheyo
 0002                   column=info:address, timestamp=1428502755349, value=Xiamen
 0002                   column=info:name, timestamp=1428502736564, value=rocky
2 row(s) in 0.0240 seconds

hbase(main):024:0>
  • 统计记录数
hbase(main):091:0> count 'user'
2 row(s) in 0.0340 seconds

=> 2
hbase(main):092:0>
  • 增加一个列,并让列的数值递增
hbase(main):103:0* incr 'user','0002','score:math'
0 row(s) in 0.0090 seconds

hbase(main):104:0> scan 'user'
ROW                     COLUMN+CELL
 0001                   column=info:address, timestamp=1428502504741, value=shenzhen
 0001                   column=info:name, timestamp=1428502495509, value=cheyo
 0001                   column=score:chinese, timestamp=1428502529395, value=95
 0001                   column=score:english, timestamp=1428502519927, value=97
 0002                   column=info:address, timestamp=1428502755349, value=Xiamen
 0002                   column=info:name, timestamp=1428502736564, value=rocky
 0002                   column=score:english, timestamp=1428502765774, value=98
 0002                   column=score:math, timestamp=1428504435991, value=\x00\x00\x00\x00
                        \x00\x00\x00\x01
2 row(s) in 0.0670 seconds

hbase(main):105:0> incr 'user','0002','score:math'
0 row(s) in 0.0080 seconds

hbase(main):106:0> scan 'user'
ROW                     COLUMN+CELL
 0001                   column=info:address, timestamp=1428502504741, value=shenzhen
 0001                   column=info:name, timestamp=1428502495509, value=cheyo
 0001                   column=score:chinese, timestamp=1428502529395, value=95
 0001                   column=score:english, timestamp=1428502519927, value=97
 0002                   column=info:address, timestamp=1428502755349, value=Xiamen
 0002                   column=info:name, timestamp=1428502736564, value=rocky
 0002                   column=score:english, timestamp=1428502765774, value=98
 0002                   column=score:math, timestamp=1428504446444, value=\x00\x00\x00\x00
                        \x00\x00\x00\x02
2 row(s) in 0.0200 seconds

hbase(main):107:0>
Tags: #HBase    Post on Hadoop