1. 启动:
在主hmaster节点上,启动hbase:
[hadoop@yun01-nn-01 hbase]$ bin/start-hbase.sh
查看守护进程:
[hadoop@yun01-nn-01 hbase]$ jps
26139 DFSZKFailoverController
26498 ResourceManager
30823 HRegionServer
30684 HMaster
25852 NameNode
30932 Jps
多了这两个进程:
30823 HRegionServer
30684 HMaster
验证:
[hadoop@yun01-nn-01 hbase]$ hbase shell
进入shell命令模式后,输入list,出现如下信息则启动成功:
hbase(main):001:0> list
TABLE
0 row(s) in 0.3930 seconds
=> []
hbase(main):002:0>
2. 基本操作
(1)建立一个表test,有三个列族name,grad和courese
hbase(main):001:0> create ‘test','name', ‘course', 'grade'
(2)插入值,命令格式:
put ‘t1′, ‘r1′, ‘c1′, ‘value', ts1
t1指表名,r1指行键名,c1指列名,value指单元格值。ts1指时间戳,一般都省略了。
put 'test', 'row1', 'name:', 'tom'
put 'test', 'row1', 'course:math', '99'
put 'test', 'row1', 'course:englist', '88'
put 'test', 'row1', 'course:sports', '77'
put 'test', 'row1', 'grade:', 'grade1'
put 'test', 'row1', 'course:math', '98'
put 'test', 'row1', 'course:physical', '97'
put 'test', 'row2', 'name:', 'kate'
put 'test', 'row2', 'course:math', '87'
put 'test', 'row2', 'course:englist', '86'
put 'test', 'row2', 'course:sports', '79'
put 'test', 'row2', 'grade:', 'grade1'
put 'test', 'row3', 'name', 'jerry'
put 'test', 'row3', 'course:math', '87'
put 'test', 'row3', 'course:englist', '86'
put 'test', 'row3', 'course:sports', '79'
put 'test', 'row3', 'grade', 'grade1'
(3)查询,命令格式:
get ‘t1′, ‘r1′
get ‘t1′, ‘r1′, {COLUMN => ‘c1′}
get ‘t1′, ‘r1′, {COLUMN => ['c1', 'c2', 'c3']}
如:
get 'test', 'row1'
get 'test', 'row1', {COLUMN=>'course:math'}
get 'test', 'row1', {COLUMN=>['course:math','course:english']}
(5)扫描指定数据
scan 'test', {COLUMNS=>['course:math','course:english']}
scan 'test', {COLUMNS=>['course:math','course:english'],LIMIT=>5}
scan 'test', {COLUMNS=>['course:math','course:english'],LIMIT=>5,STARTROW=>'row2'}
(6)删除指定数据
命令格式:
delete ‘t1′, ‘r1′, ‘c1′, ts1
如:
delete ‘test','row3','grade'
(6)增加一个列族
disable 'test'
alter 'test', NAME=>'hour'
enable 'test'
(7)删除一个列族:
alter 'test',{NAME=>'hour',METHOD=>'delete'}
(8)统计行数:
hbase> count 'test'
(9)表的删除
先停止表的可使用性,然后执行删除命令。
disable 'test1'
drop 'test1'
(10) 查看表是否存在
hbase(main):010:0> exists 'test1'
Table test1 does not exist
0 row(s) in 0.0240 seconds
(11) 列出所有表
list
(12)判断表是否enable
hbase(main):014:0> is_enabled 'test'
true
0 row(s) in 0.0270 seconds