hbase常用的shell命令例子__hbase

來源:互聯網
上載者:User

1、hbase shell    進入hbase [ hadoop@mdw ~]$  hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.16, r1557241, Fri Jan 10 20:10:24 UTC 2014

2、whoami    查看當前訪問hbase的使用者 hbase(main):001:0>  whoami hadoop
3、version    查看當前hbase的版本資訊 hbase(main):002:0>  version 0.94.16, r1557241, Fri Jan 10 20:10:24 UTC 2014
4、status    查看當前hbase的狀態 hbase(main):003:0>  status 2 servers, 0 dead, 1.0000 average load 也可以通過增加參數查看,status 'simple' 查看簡單的資訊、status 'summary' 查看概要資訊、status 'detailed' 查看詳細資料
5、create    建立表 hbase(main):007:0>  create 'member','member_id','address','info' 0 row(s) in 1.1590 seconds

6、list    查看資料庫中的表 hbase(main):008:0>  list TABLE                                                                                                     member                                                                                                   1 row(s) in 0.0280 seconds

7、describe 表名    查看錶的資訊 hbase(main):009:0> describe member NameError: undefined local variable or method `member' for #<Object:0x453c47> hbase(main):010:0> describe 'member' DESCRIPTION                                                                                                                  ENABLED                              'member', {NAME => ' address', DATA_BLOCK_ENCODING => 'NONE', BLOOMF    true                                  ILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRES                                      SION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELE                                      TED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', E                                      NCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}, {NAME => ' info', DA                                      TA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCO                                      PE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS =>                                        '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE                                        => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCA                                      CHE => 'true'}, {NAME => ' member_id', DATA_BLOCK_ENCODING => 'NONE'                                      , BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3',                                       COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', K                                      EEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'f                                      alse', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}                                                   1 row(s) in 0.0450 seconds hbase(main):011:0>
8、刪除列族 刪除列族 需要先禁用表,否則會報以下錯誤: hbase(main):006:0>  alter 'member',NAME=>'member_id',METHOD=>'delete' ERROR: org.apache.hadoop.hbase.TableNotDisabledException: org.apache.hadoop.hbase.TableNotDisabledException: member         at org.apache.hadoop.hbase.master.HMaster.checkTableModifiable(HMaster.java:1525)         at org.apache.hadoop.hbase.master.handler.TableEventHandler.<init>(TableEventHandler.java:72)         at org.apache.hadoop.hbase.master.handler.TableDeleteFamilyHandler.<init>(TableDeleteFamilyHandler.java:41)         at org.apache.hadoop.hbase.master.HMaster.deleteColumn(HMaster.java:1430)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)         at java.lang.reflect.Method.invoke(Method.java:597)         at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Server.call(WritableRpcEngine.java:323)         at org.apache.hadoop.hbase.ipc.HBaseServer$Handler.run(HBaseServer.java:1426)
刪除列族的正確方法: 先禁用表: hbase(main):007:0>  disable 'member' 0 row(s) in 1.1690 seconds
然後刪除列族(注意NAME和METHOD要大寫): hbase(main):008:0>  alter 'member',NAME=>'member_id',METHOD=>'delete' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 1.1640 seconds
刪除列族之後再啟用表: hbase(main):009:0>  enable 'member' 0 row(s) in 1.2250 seconds
再次查看錶資訊,便可以發現member_id已經被刪除 hbase(main):010:0> describe 'member' DESCRIPTION                                                                                                                                                                                            ENABLED                                                      'member', {NAME => ' address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '     true                                                         0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS =                                                             > 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}, {N                                                             AME => ' info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS =>                                                               '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOC                                                             KSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}                                                                               1 row(s) in 0.0420 seconds

9、drop 表名    刪除表 刪除表時也需要先將表disable,否則會報錯,為方便先建立個暫存資料表(user表),然後將user表刪除 hbase(main):019:0> create 'user','name','age'  0 row(s) in 1.0900 seconds
沒有禁用user表,直接刪除,報以下錯誤: hbase(main):020:0>  drop 'user' ERROR: Table user is enabled. Disable it first.' Here is some help for this command: Drop the named table. Table must first be disabled: e.g. "hbase> drop 't1'"
正確刪除方法如下: 先禁用表: hbase(main):021:0>  disable 'user' 0 row(s) in 1.1660 seconds 然後刪除表: hbase(main):022:0>  drop 'user' 0 row(s) in 1.0710 seconds hbase(main):023:0> 
10、exists 表名    查看一個表是否存在 hbase(main):023:0>  exists 'user' Table user  does not exist                                                                                 0 row(s) in 0.0230 seconds
hbase(main):024:0>  exists 'member' Table member  does exist                                                                                   0 row(s) in 0.0750 seconds
11、is_enabled    判斷表是否enable hbase(main):025:0>  is_enabled 'member' true                                                                                                     0 row(s) in 0.0160 seconds
12、is_disabled    判斷表是否disable hbase(main):026:0>  is_disabled 'member' false                                                                                                     0 row(s) in 0.0220 seconds
13、put    插入資料 hbase(main):076:0>  put 'member','xueba','info:age','25' 0 row(s) in 0.0170 seconds
為了方便使用下面命令的,這裡多插入一些資料:

put 'member','xueba','info:age','25'

put 'member','xueba','info:birthday','1989-06-19'

put 'member','xueba','info:company','tecent'

put 'member','xueba','address:contry','china'

put 'member','xueba','address:province','guangdong'

put 'member','xueba','address:city','shenzhen'

put 'member','xiaoming','info:age','24'

put 'member','xiaoming','info:birthday','1990-03-22'

put 'member','xiaoming','info:company','tecent'

put 'member','xiaoming','info:favorite','movie'

put 'member','xiaoming','address:contry','china'

put 'member','xiaoming','address:province','guangdong'

put 'member','xiaoming','address:city','guangzhou'
14、get    擷取表資料 擷取xueba的資訊: hbase(main):090:0>  get 'member','xueba' COLUMN                      CELL                                                                          address:city               timestamp=1436932081705, value=shenzhen                                        address:contry             timestamp=1436932081662, value=china             &n

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.