建立表,表名hbase_1102,HBase表是由Key-Value组成的,此表中Key为NAME
code
此表有两个列族,CF1和CF2,其中CF1和CF2下分别有两个列name和gender,Chinese和Math
1,建立表hbase_1102有两个列族CF1和CF2blog
hbase(main):041:0> create 'hbase_1102', {NAME=>'cf1'}, {NAME=>'cf2'}
2,向表中添加数据,在想HBase的表中添加数据的时候,只能一列一列的添加,不能同时添加多列。图片
hbase(main):042:0> put'hbase_1102', '001','cf1:name','Tom' hbase(main):043:0> put'hbase_1102', '001','cf1:gender','man' hbase(main):044:0> put'hbase_1102', '001','cf2:chinese','90' hbase(main):045:0> put'hbase_1102', '001','cf2:math','91'
这样表结构就起来了,其实比较自由,列族里边能够自由添加子列很方便。若是列族下没有子列,加不加冒号都是能够的。get
若是在添加数据的时候,须要手动的设置时间戳,则在put命令的最后加上相应的时间戳,时间戳是long类型的,因此不须要加引号file
hbase(main):045:0> put'hbase_1102', '001','cf2:math','91',1478053832459
3,查看表中的全部数据im
hbase(main):046:0> scan 'hbase_1102' ROW COLUMN+CELL 001 column=cf1:gender, timestamp=1478053832459, value=man 001 column=cf1:name, timestamp=1478053787178, value=Tom 001 column=cf2:chinese, timestamp=1478053848225, value=90001 column=cf2:math, timestamp=1478053858144, value=911 row(s) in0.0140seconds
4,查看其中某一个Key的数据时间戳
hbase(main):048:0> get'hbase_1102','001' COLUMN CELL cf1:gender timestamp=1478053832459, value=man cf1:name timestamp=1478053787178, value=Tom cf2:chinese timestamp=1478053848225, value=90 cf2:math timestamp=1478053858144, value=914 row(s) in0.0290seconds