HBase Shell
hadoop@muhe221:~/soft/hbase-2.1.3/bin$ hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/home/hadoop/soft/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/home/hadoop/soft/hbase-2.1.3/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] HBase Shell Use "help" to get list of supported commands. Use "exit" to quit this interactive shell. For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell Version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019 Took 0.0041 seconds hbase(main):001:0> hbase(main):135:0> create 'mytable', 'f1', 'f2', 'f3' #创建表 Created table mytable Took 2.3374 seconds => Hbase::Table - mytable hbase(main):137:0> list #列出所有表 TABLE mytable 1 row(s) Took 0.0043 seconds => ["mytable"] hbase(main):138:0> describe 'mytable' #查看表描述 Table mytable is ENABLED mytable COLUMN FAMILIES DESCRIPTION {NAME => 'f1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', RE PLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '6553 6'} {NAME => 'f2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', RE PLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '6553 6'} {NAME => 'f3', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', RE PLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '6553 6'} 3 row(s) Took 0.0170 seconds hbase(main):141:0> put 'mytable', '1', 'f1', '11' #插入一个数据 Took 0.0095 seconds hbase(main):142:0> scan 'mytable' #查看表内容 ROW COLUMN+CELL 1 column=f1:, timestamp=1553217726797, value=11 1 row(s) Took 0.0041 seconds hbase(main):143:0> put 'mytable', '1', 'f2', '12' Took 0.0037 seconds hbase(main):144:0> put 'mytable', '1', 'f3', '13' Took 0.0084 seconds hbase(main):145:0> put 'mytable', '2', 'f1', '21' Took 0.0032 seconds hbase(main):146:0> put 'mytable', '2', 'f2', '22' Took 0.0042 seconds hbase(main):147:0> put 'mytable', '2', 'f3', '23' Took 0.0040 seconds hbase(main):148:0> hbase(main):149:0* scan 'mytable' ROW COLUMN+CELL 1 column=f1:, timestamp=1553217726797, value=11 1 column=f2:, timestamp=1553217745567, value=12 1 column=f3:, timestamp=1553217755111, value=13 2 column=f1:, timestamp=1553217774697, value=21 2 column=f2:, timestamp=1553217787157, value=22 2 column=f3:, timestamp=1553217793882, value=23 2 row(s) Took 0.0095 seconds hbase(main):150:0> disable 'mytable' #禁用表 Took 2.3724 seconds hbase(main):151:0> drop 'mytable' #删除表之前必须先禁用表 Took 0.8300 seconds hbase(main):152:0>
get 获取行或者单元的值
hbase(main):020:0* status 1 active master, 0 backup masters, 2 servers, 0 dead, 1.5000 average load Took 0.1048 seconds hbase(main):021:0> version 2.1.3, rda5ec9e4c06c537213883cca8f3cc9a7c19daf67, Mon Feb 11 15:45:33 CST 2019 Took 0.0002 seconds hbase(main):022:0> whoami hadoop (auth:SIMPLE) groups: hadoop Took 0.0094 seconds hbase(main):024:0> exists 'mytable' #判断表是否存在 Table mytable does exist Took 0.0301 seconds => true hbase(main):025:0> is_enabled "mytable" #判断表是否被启用 true Took 0.0070 seconds => true hbase(main):026:0> disable 'mytable' #禁用表 Took 1.3882 seconds hbase(main):027:0> is_enabled "mytable" false Took 0.0085 seconds => false hbase(main):028:0> enable 'mytable' #启用表 Took 2.3174 seconds hbase(main):029:0> is_enabled "mytable" true Took 0.0059 seconds => true hbase(main):065:0> scan 'mytable' ROW COLUMN+CELL 1 column=f1:, timestamp=1553221153576, value=11 1 column=f2:, timestamp=1553310919755, value=12 2 column=f1:, timestamp=1553311065652, value=21 2 column=f2:, timestamp=1553311073483, value=22 2 row(s) hbase(main):115:0* scan 'mytable', {COLUMNS=>'f1'} ROW COLUMN+CELL 1 column=f1:, timestamp=1553311815331, value=11 2 column=f1:, timestamp=1553311065652, value=21 2 row(s) hbase(main):069:0* get 'mytable', '1', 'f1' #读取某个值 COLUMN CELL f1: timestamp=1553221153576, value=11 1 row(s) Took 0.0104 seconds hbase(main):070:0> get 'mytable', '1' #读取某行 COLUMN CELL f1: timestamp=1553221153576, value=11 f2: timestamp=1553310919755, value=12 1 row(s) Took 0.0106 seconds Took 0.0068 seconds hbase(main):132:0> scan 'mytable', {COLUMNS =>'f2', LIMIT=>1} ROW COLUMN+CELL 1 column=f2:, timestamp=1553310919755, value=12 1 row(s) Took 0.0070 seconds
hbase(main):138:0> create 'table', 'c1', 'c2' hbase(main):216:0> put 'table', 'r1', 'c1:1', 'r1c111' Took 0.0030 seconds hbase(main):217:0> put 'table', 'r1', 'c1:2', 'r1c121' Took 0.0031 seconds hbase(main):220:0* put 'table', 'r2', 'c1:1', 'r1c112' Took 0.0030 seconds hbase(main):221:0> put 'table', 'r2', 'c1:2', 'r1c122' Took 0.0027 seconds hbase(main):222:0> scan 'table' ROW COLUMN+CELL r1 column=c1:1, timestamp=1553323187635, value=r1c111 r1 column=c1:2, timestamp=1553323209410, value=r1c121 r2 column=c1:1, timestamp=1553323264565, value=r1c112 r2 column=c1:2, timestamp=1553323275000, value=r1c122 2 row(s) hbase(main):232:0* scan 'table', {COLUMNS => "c1"} ROW COLUMN+CELL r1 column=c1:1, timestamp=1553323187635, value=r1c111 r1 column=c1:2, timestamp=1553323209410, value=r1c121 r2 column=c1:1, timestamp=1553323264565, value=r1c112 r2 column=c1:2, timestamp=1553323275000, value=r1c122 2 row(s) Took 0.0052 seconds hbase(main):233:0> scan 'table', {COLUMNS => "c1:1"} ROW COLUMN+CELL r1 column=c1:1, timestamp=1553323187635, value=r1c111 r2 column=c1:1, timestamp=1553323264565, value=r1c112 2 row(s) Took 0.0032 seconds hbase(main):234:0> scan 'table', {COLUMNS => "c1:2"} ROW COLUMN+CELL r1 column=c1:2, timestamp=1553323209410, value=r1c121 r2 column=c1:2, timestamp=1553323275000, value=r1c122 2 row(s) hbase(main):250:0> scan 'table', {COLUMNS => "c1:2", LIMIT => 1} ROW COLUMN+CELL r1 column=c1:2, timestamp=1553323209410, value=r1c121 1 row(s) Took 0.0042 seconds hbase(main):239:0* get 'table', 'r1', {COLUMN => 'c1:1'} COLUMN CELL c1:1 timestamp=1553323187635, value=r1c111 1 row(s) Took 0.0028 seconds hbase(main):240:0> get 'table', 'r1', {COLUMN => 'c1'} COLUMN CELL c1:1 timestamp=1553323187635, value=r1c111 c1:2 timestamp=1553323209410, value=r1c121 1 row(s)

浙公网安备 33010602011771号