[hdfs@hadoop1 root]$ hbase
Usage: hbase [<options>] <command> [<args>]
Options:
--config DIR Configuration direction to use. Default: ./conf
--hosts HOSTS Override the list in ‘regionservers‘ file
Commands:
Some commands take arguments. Pass no args or -h for usage.
shell Run the HBase shell
hbck Run the hbase ‘fsck‘ tool
hlog Write-ahead-log analyzer
hfile Store file analyzer
zkcli Run the ZooKeeper shell
upgrade Upgrade hbase
master Run an HBase HMaster node
regionserver Run an HBase HRegionServer node
zookeeper Run a Zookeeper server
rest Run an HBase REST server
thrift Run the HBase Thrift server
thrift2 Run the HBase Thrift2 server
clean Run the HBase clean up script
classpath Dump hbase CLASSPATH
mapredcp Dump CLASSPATH entries required by mapreduce
pe Run PerformanceEvaluation
ltt Run LoadTestTool
version Print the version
CLASSNAME Run the class named CLASSNAME
[root@hadoop1 ~]# hbase shell
hbase(main):001:0> exit
hbase(main):001:0> list
TABLE
0 row(s) in 1.9500 seconds
=> []
create ‘表名称‘,‘列名称1‘,...,‘列名称n‘
eg:建立一个表scores,有两个列族grad和courese。
hbase(main):004:0> create ‘scores‘,‘grad‘,‘courese‘
0 row(s) in 1.5820 seconds
=> Hbase::Table - scores
hbase(main):005:0> list
TABLE
scores
1 row(s) in 0.0080 seconds
=> ["scores"]
put ‘表名‘,‘行键名‘,‘列名‘,‘单元格值‘,‘时间戳‘
时间戳可以省略。
hbase(main):009:0> put ‘scores‘,‘Tom‘,‘grad:‘,‘5‘
hbase(main):011:0> put ‘scores‘,‘Tom‘,‘courese:math‘,‘100‘
hbase(main):012:0> put ‘scores‘,‘Tom‘,‘courese:art‘,‘100‘
hbase(main):013:0> put ‘scores‘,‘Mark‘,‘grad‘,‘6‘
hbase(main):014:0> put ‘scores‘,‘Mark‘,‘courese:english‘,‘120‘
hbase(main):015:0> put ‘scores‘,‘Mark‘,‘courese:chinese‘,‘108‘
scan ‘scores‘
hbase(main):020:0> get ‘scores‘,‘Mark‘
COLUMN CELL
courese:chinese timestamp=1435491529683, value=108
courese:english timestamp=1435491508206, value=120
grad: timestamp=1435491484521, value=6
3 row(s) in 0.0520 seconds
hbase(main):021:0> get ‘scores‘,‘Mark‘,‘grad‘
COLUMN CELL
grad: timestamp=1435491484521, value=6
1 row(s) in 0.0390 seconds
修改数据存储的版本
hbase> count ‘ns1:t1‘
hbase> count ‘t1‘
hbase> count ‘t1‘, INTERVAL => 100000
hbase> count ‘t1‘, CACHE => 1000
hbase> count ‘t1‘, INTERVAL => 10, CACHE => 1000
统计一般比较耗时,使用mapreduce进行统计,统计结果会缓存,默认是10行,统计间隔默认是1000行。
hbase(main):038:0> count ‘scores‘
2 row(s) in 0.0290 seconds
=> 2
增加一列族
hbase(main):048:0> alter ‘scores‘,NAME=>‘info‘
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.4330 seconds
删除一个列族
hbase(main):053:0> alter ‘scores‘,NAME=>‘NAME=info‘,METHOD=>‘delete‘
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.4670 seconds
hbase(main):055:0> alter ‘scores‘,‘delete‘=>‘courese‘
不过不能删除掉,先disable ‘scores‘
,修改完之后再enable ‘scores‘
。
先禁用表
hbase(main):057:0> disable ‘scores‘
然后删除表
hbase(main):057:0> drop ‘scores‘
delete ‘scores‘,‘Mark‘,‘courese:english‘
deleteall ‘表名‘,‘行键‘
deleteall ‘scores‘,‘Mark‘(慎用)
表结构仍然在。
truncate ‘scores‘
原文地址:http://blog.csdn.net/scgaliguodong123_/article/details/46626779