hbase提供了一個shell的終端給用戶交互。使用命令hbase shell進入命令界面。經過執行 help能夠看到命令的幫助信息。linux
以網上的一個學生成績表的例子來演示hbase的用法。shell
name | grad | course | |
math | art | ||
Tom | 5 | 97 | 87 |
Jim | 4 | 89 | 80 |
這裏grad對於表來講是一個只有它本身的列族,course對於表來講是一個有兩個列的列族,這個列族由兩個列組成math和art,固然咱們能夠根據咱們的須要在course中創建更多的列族,如computer,physics等相應的列添加入course列族。apache
(1)創建一個表scores,有兩個列族grad和courese緩存
hbase(main):001:0> create ‘scores','grade', ‘course'
put ‘scores','Tom','grade:','5′ put ‘scores','Tom','course:math','97′ put ‘scores','Tom','course:art','87′ put ‘scores','Jim','grade','4′ put ‘scores','Jim','course:','89′ put ‘scores','Jim','course:','80′
hbase> put ‘t1′, ‘r1′, ‘c1′, ‘value', ts1
get ‘scores','Jim' get ‘scores','Jim','grade'
hbase> get ‘t1′, ‘r1′ hbase> get ‘t1′, ‘r1′, {TIMERANGE => [ts1, ts2]} hbase> get ‘t1′, ‘r1′, {COLUMN => ‘c1′} hbase> get ‘t1′, ‘r1′, {COLUMN => ['c1', 'c2', 'c3']} hbase> get ‘t1′, ‘r1′, {COLUMN => ‘c1′, TIMESTAMP => ts1} hbase> get ‘t1′, ‘r1′, {COLUMN => ‘c1′, TIMERANGE => [ts1, ts2], VERSIONS => 4} hbase> get ‘t1′, ‘r1′, {COLUMN => ‘c1′, TIMESTAMP => ts1, VERSIONS => 4} hbase> get ‘t1′, ‘r1′, ‘c1′ hbase> get ‘t1′, ‘r1′, ‘c1′, ‘c2′ hbase> get ‘t1′, ‘r1′, ['c1', 'c2']
scan ‘scores'
hbase> scan ‘.META.' hbase> scan ‘.META.', {COLUMNS => ‘info:regioninfo'} hbase> scan ‘t1′, {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => ‘xyz'} hbase> scan ‘t1′, {COLUMNS => ‘c1′, TIMERANGE => [1303668804, 1303668904]} hbase> scan ‘t1′, {FILTER => 「(PrefixFilter (‘row2′) AND (QualifierFilter (>=, ‘binary:xyz'))) AND (TimestampsFilter ( 123, 456))」} hbase> scan ‘t1′, {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}
delete ‘scores','Jim','grade' delete ‘scores','Jim'
hbase> delete ‘t1′, ‘r1′, ‘c1′, ts1
disable ‘scores' alter ‘scores',NAME=>'info' enable ‘scores'
hbase> alter ‘t1′, NAME => ‘f1′, VERSIONS => 5
hbase> alter ‘t1′, NAME => ‘f1′, METHOD => ‘delete' hbase> alter ‘t1′, ‘delete' => ‘f1′
MEMSTORE_FLUSHSIZE, READONLY,和 DEFERRED_LOG_FLUSH: hbase> alter ‘t1′, METHOD => ‘table_att', MAX_FILESIZE => '134217728′
hbase> alter ‘t1′, METHOD => ‘table_att', ‘coprocessor'=> ‘hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2′
[coprocessor jar file location] | class name | [priority] | [arguments]
hbase> alter ‘t1′, METHOD => ‘table_att_unset', NAME => ‘MAX_FILESIZE' hbase> alter ‘t1′, METHOD => ‘table_att_unset', NAME => ‘coprocessor$1′
hbase> alter ‘t1′, {NAME => ‘f1′}, {NAME => ‘f2′, METHOD => ‘delete'}
hbase> count ‘t1′ hbase> count ‘t1′, INTERVAL => 100000 hbase> count ‘t1′, CACHE => 1000 hbase> count ‘t1′, INTERVAL => 10, CACHE => 1000
drop ‘t1′
COMMAND GROUPS: Group name: general Commands: status, version Group name: ddl Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, is_disabled, is_enabled, list, show_filters Group name: dml Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate Group name: tools Commands: assign, balance_switch, balancer, close_region, compact, flush, hlog_roll, major_compact, move, split, unassign, zk_dump Group name: replication Commands: add_peer, disable_peer, enable_peer, list_peers, remove_peer, start_replication, stop_replication Group name: security Commands: grant, revoke, user_permission
$ hbase shell test.hbaseshell