1) 表设计
2) 建表scores,具有两个列族:grad和course
[root@master bin]# hbase shell
hbase(main):002:0> create 'scores','grade','course'
0 row(s) in 7.6340 seconds
=> Hbase::Table - scores
3) 查看Hasee中有哪些表
hbase(main):003:0> list
TABLE
scores
1 row(s) in 0.2190 seconds
=> ["scores"]
4) 查看表结构
hbase(main):004:0> describe 'scores'
Table scores is ENABLED
scores
COLUMN FAMILIES DESCRIPTION
{NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NON
E', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}
{NAME => 'grade', 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 => 'tr
ue'}
2 row(s) in 0.5300 seconds
5) 添加数据
a) 行名称为 Tom 列名为grad, 值为1
hbase(main):005:0> put 'scores','Tom','grade:','1'
b) 给Tom这一行的数据的列族添加一列
hbase(main):005:0> put 'scores','Tom','course:math','93'
c) 给Tom这一行的数据的列族添加一列
hbase(main):005:0> put 'scores','Tom','course:art','82'
d) 行名称为 Sam 列名为grad, 值为2
hbase(main):005:0> put 'scores','Sam','grade:','2'
e) 给Sam这一行的数据的列族添加一列
hbase(main):005:0> put 'scores','Sam','course:math','97'
f) 给Sam这一行的数据的列族添加一列
hbase(main):005:0> put 'scores','Sam','course:art','76'
6) 查看scores表中Tom的相关数据
hbase(main):014:0> get 'scores','Tom'
COLUMN CELL
course:art timestamp=1453694601377, value=76
course:math timestamp=1453694113182, value=93
grade: timestamp=1453694015658, value=1
3 row(s) in 0.0190 seconds
7) 查看scores表中所有数据
hbase(main):015:0> scan 'scores'
ROW COLUMN+CELL
Sam column=course:art, timestamp=1453694637826, value=82
Sam column=course:math, timestamp=1453694531258, value=97
Sam column=grade:, timestamp=1453694479156, value=2
Tom column=course:art, timestamp=1453694601377, value=76
Tom column=course:math, timestamp=1453694113182, value=93
Tom column=grade:, timestamp=1453694015658, value=1
2 row(s) in 0.1770 seconds
8) 查看scores表中所有数据courses列族的所有数据
hbase(main):015:0> scan "scores",{COLUMNS => ['course:math']}
hbase(main):015:0> scan "scores",{COLUMNS => ['course']}
ROW COLUMN+CELL
Sam column=course:art, timestamp=1453694637826, value=82
Sam column=course:math, timestamp=1453694531258, value=97
Tom column=course:art, timestamp=1453694601377, value=76
Tom column=course:math, timestamp=1453694113182, value=93
2 row(s) in 0.0250 seconds
9) delete表记录
hbase(main):015:0> delete 'scores','Tom','course:ctrl'
10) count表记录
hbase(main):025:0> count 'scores'
2 row(s) in 0.1310 seconds
=> 2
11) exists表
hbase(main):027:0> exists 'scores'
Table scores does exist
0 row(s) in 0.0120 seconds