1、首先要打开hbase,使用jps查看进程
jps是java进程状态工具,它会返回进程ID和服务名称
[email protected]:~/Apache/hbase-0.94.15-security$ jps
3082 NameNode
6245 HRegionServer
3493 JobTracker
6064 HMaster
5999 HQuorumPeer
3638 TaskTracker
3259 DataNode
3413 SecondaryNameNode
6320 Jps
2、运行hbase shell
启动hbase-shell:进入bin目录下,输入./hbase shell
status:hbase(main):022:0> status
1 servers, 0 dead, 2.0000 average load
version:hbase(main):023:0> version
0.94.15, r1551829, Wed Dec 18 19:15:20 UTC 2013
whoami:hbase(main):024:0> whoami
chen
3、数据定义命令
list:查看当前hbase有哪些表
hbase(main):002:0> list
TABLE
Employee
1 row(s) in 0.0700 seconds
create:create ‘表名‘,‘列名‘,‘列名‘...
hbase(main):001:0> create ‘Employee‘,‘lie‘
0 row(s) in 3.4890 seconds
describe:查看表的构造
enable/disable:禁用或者启动表,在改变表之前要禁用表
drop:删除表
4、数据操作和检索命令
put:加入一行数据:put ‘表名‘,‘命名的行名‘,‘已命名的列名:‘,‘值‘;
给某一行的列族添加一列:put ‘表名‘,‘已命名的行名‘,‘已命名的列名:命名的列名‘,‘值‘(就是将某一列继续细分为多个列,例如成绩列可分为数学成绩、英语成绩等)
hbase(main):004:0> put ‘Employee‘,‘Record1‘,‘lie:EmpId‘,‘1001‘
0 row(s) in 0.0240 seconds
get:查看某表中某行的数据get ‘表名‘,‘行名‘
hbase(main):007:0> get ‘Employee‘,‘Record1‘
COLUMN CELL
lie:Address timestamp=1463665484970, value=Bangalore
lie:EmpId timestamp=1463665379589, value=1001
lie:EmpName timestamp=1463665461795, value=Henry
3 row(s) in 0.1030 seconds
scan:查看某表中所有数据scan ‘表名‘,查看scores表中某列的数据scan ‘表名‘,{COLUMNS=>‘course‘}
hbase(main):008:0> scan ‘Employee‘
ROW COLUMN+CELL
Record1 column=lie:Address, timestamp=1463665484970, value=Bangalo
re
Record1 column=lie:EmpId, timestamp=1463665379589, value=1001
Record1 column=lie:EmpName, timestamp=1463665461795, value=Henry
1 row(s) in 0.0870 seconds
【注意:scan命令可以指定startrow,stoprow来scan多个row,例如:scan ‘user_test‘,{COLUMNS
=>‘info:username‘,LIMIT =>10, STARTROW => ‘test‘,STOPROW=>‘test2‘}】