通过使用HBase Shell,用命令行和HBase进行交互。
1、启动HBase Shell
[xxxx@localhost bin]$ ./hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.24, r68ed793a1d89226f8fb1ee1ee618c1e7779d46cd, Mon Sep 29 23:09:31 UTC 2014
hbase(main):001:0>
2、查看Hbase中的表
hbase(main):001:0> list
TABLE
mytable
mytable2
2 row(s) in 0.4670 seconds
hbase(main):002:0>
3、创建表,testtable:表名,cf:列族
hbase(main):002:0> create 'testtable','cf'
0 row(s) in 1.4170 seconds
hbase(main):003:0> list
TABLE
mytable
mytable2
testtable
3 row(s) in 0.0240 seconds
hbase(main):004:0>
4、写数据
hbase(main):004:0> put 'testtable','first','cf:message','hello Hbase'
0 row(s) in 0.0610 seconds
hbase(main):005:0> put 'testtable','second','cf:foo',0x0
0 row(s) in 0.0160 seconds
hbase(main):006:0> put 'testtable','third','cf:bar',3.1415926
0 row(s) in 0.0230 seconds
hbase(main):007:0>
5、读数据
hbase(main):013:0> get 'testtable','first'
COLUMN CELL
cf:message timestamp=1419268133154, value=hello Hbase
1 row(s) in 0.0150 seconds
hbase(main):014:0> scan 'testtable'
ROW COLUMN+CELL
first column=cf:message, timestamp=1419268133154, value=hello Hbase
second column=cf:foo, timestamp=1419268974405, value=0
third column=cf:bar, timestamp=1419268992995, value=3.1415926
3 row(s) in 0.0470 seconds
hbase(main):015:0>