HBase Shell 命令

This page describes the JRuby IRB-based HBase Shell. It replaces the SQL-like HQL, the Shell found in HBase versions 0.1.x and previous. Some discussion of new shell requirements can be found in the Shell Replacementdocument.

To run the shell, do  

 

Shell代码   收藏代码
  1. hadoop$redhat ${HBASE_HOME}/bin/hbase shell  

 

You'll be presented with a prompt like the following:

Shell代码   收藏代码
  1. HBase Shell; enter 'help<RETURN>' for list of supported commands.  
  2. Version: 0.2.0-dev, r670701, Mon Jun 23 17:26:36 PDT 2008  
  3. hbase(main):001:0>  

 

Type 'help' followed by a return to get a listing of commands

Shell代码   收藏代码
  1. hbase(main):001:0> help  
  2. HBASE SHELL COMMANDS:  
  3.  alter     Alter column family schema;  pass table name and a dictionary  
  4.            specifying new column family schema. Dictionaries are described  
  5.            below in the GENERAL NOTES section.  Dictionary must include name  
  6.            of column family to alter.  For example,  
  7.   
  8.            To change or add the 'f1' column family in table 't1' from defaults  
  9.            to instead keep a maximum of 5 cell VERSIONS, do:  
  10.            hbase> alter 't1', {NAME => 'f1', VERSIONS => 5}  
  11.   
  12.            To delete the 'f1' column family in table 't1', do:  
  13.            hbase> alter 't1', {NAME => 'f1', METHOD => 'delete'}  
  14.   
  15.            You can also change table-scope attributes like MAX_FILESIZE  
  16.            MEMSTORE_FLUSHSIZE and READONLY.  
  17.   
  18.            For example, to change the max size of a family to 128MB, do:  
  19.            hbase> alter 't1', {METHOD => 'table_att', MAX_FILESIZE => '134217728'}  
  20.   
  21.  count     Count the number of rows in a table. This operation may take a LONG  
  22.            time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a  
  23.            counting mapreduce job). Current count is shown every 1000 rows by  
  24.            default. Count interval may be optionally specified. Examples:  
  25.   
  26.            hbase> count 't1'  
  27.            hbase> count 't1'100000  
  28.   
  29.  create    Create table; pass table name, a dictionary of specifications per  
  30.            column family, and optionally a dictionary of table configuration.  
  31.            Dictionaries are described below in the GENERAL NOTES section.  
  32.            Examples:  
  33.   
  34.            hbase> create 't1', {NAME => 'f1', VERSIONS => 5}  
  35.            hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}  
  36.            hbase> # The above in shorthand would be the following:  
  37.            hbase> create 't1''f1''f2''f3'  
  38.            hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, \  
  39.              BLOCKCACHE => true}  
  40.   
  41.  describe  Describe the named table: e.g. "hbase> describe 't1'"  
  42.   
  43.  delete    Put a delete cell value at specified table/row/column and optionally  
  44.            timestamp coordinates.  Deletes must match the deleted cell's  
  45.            coordinates exactly.  When scanning, a delete cell suppresses older  
  46.            versions. Takes arguments like the 'put' command described below  
  47.   
  48.  deleteall Delete all cells in a given row; pass a table name, row, and optionally  
  49.            a column and timestamp  
  50.   
  51.  disable   Disable the named table: e.g. "hbase> disable 't1'"  
  52.   
  53.  drop      Drop the named table. Table must first be disabled. If table has  
  54.            more than one region, run a major compaction on .META.:  
  55.   
  56.            hbase> major_compact ".META."  
  57.   
  58.  enable    Enable the named table  
  59.   
  60.  exists    Does the named table exist? e.g. "hbase> exists 't1'"  
  61.   
  62.  exit      Type "hbase> exit" to leave the HBase Shell  
  63.   
  64.  get       Get row or cell contents; pass table name, row, and optionally  
  65.            a dictionary of column(s), timestamp and versions.  Examples:  
  66.   
  67.            hbase> get 't1''r1'  
  68.            hbase> get 't1''r1', {COLUMN => 'c1'}  
  69.            hbase> get 't1''r1', {COLUMN => ['c1''c2''c3']}  
  70.            hbase> get 't1''r1', {COLUMN => 'c1', TIMESTAMP => ts1}  
  71.            hbase> get 't1''r1', {COLUMN => 'c1', TIMESTAMP => ts1, \  
  72.              VERSIONS => 4}  
  73.   
  74.  list      List all tables in hbase  
  75.   
  76.  put       Put a cell 'value' at specified table/row/column and optionally  
  77.            timestamp coordinates.  To put a cell value into table 't1' at  
  78.            row 'r1' under column 'c1' marked with the time 'ts1', do:  
  79.   
  80.            hbase> put 't1''r1''c1''value', ts1  
  81.   
  82.  tools     Listing of hbase surgery tools  
  83.   
  84.  scan      Scan a table; pass table name and optionally a dictionary of scanner  
  85.            specifications.  Scanner specifications may include one or more of  
  86.            the following: LIMIT, STARTROW, STOPROW, TIMESTAMP, or COLUMNS.  If  
  87.            no columns are specified, all columns will be scanned.  To scan all  
  88.            members of a column family, leave the qualifier empty as in  
  89.            'col_family:'.  Examples:  
  90.   
  91.            hbase> scan '.META.'  
  92.            hbase> scan '.META.', {COLUMNS => 'info:regioninfo'}  
  93.            hbase> scan 't1', {COLUMNS => ['c1''c2'], LIMIT => 10, \  
  94.              STARTROW => 'xyz'}  
  95.   
  96.            For experts, there is an additional option -- CACHE_BLOCKS -- which  
  97.            switches block caching for the scanner on (true) or off (false).  By  
  98.            default it is enabled.  Examples:  
  99.   
  100.            hbase> scan 't1', {COLUMNS => ['c1''c2'], CACHE_BLOCKS => false}  
  101.   
  102.  status    Show cluster status. Can be 'summary''simple', or 'detailed'. The  
  103.            default is 'summary'. Examples:  
  104.   
  105.            hbase> status  
  106.            hbase> status 'simple'  
  107.            hbase> status 'summary'  
  108.            hbase> status 'detailed'  
  109.   
  110.  shutdown  Shut down the cluster.  
  111.   
  112.  truncate  Disables, drops and recreates the specified table.  
  113.   
  114.  version   Output this HBase version  
  115.   
  116. GENERAL NOTES:  
  117. Quote all names in the hbase shell such as table and column names.  Don't  
  118. forget commas delimit command parameters.  Type <RETURN> after entering a  
  119. command to run it.  Dictionaries of configuration used in the creation and  
  120. alteration of tables are ruby Hashes. They look like this:  
  121.   
  122.   {'key1' => 'value1''key2' => 'value2', ...}  
  123.   
  124. They are opened and closed with curley-braces.  Key/values are delimited by  
  125. the '=>' character combination.  Usually keys are predefined constants such as  
  126. NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type  
  127. 'Object.constants' to see a (messy) list of all constants in the environment.  
  128.   
  129. In case you are using binary keys or values and need to enter them into the  
  130. shell then use double-quotes to make use of hexadecimal or octal notations,  
  131. for example:  
  132.   
  133.   hbase> get 't1'"key\x03\x3f\xcd"  
  134.   hbase> get 't1'"key\003\023\011"  
  135.   hbase> put 't1'"test\xef\xff"'f1:'"\x01\x33\x40"  
  136.   
  137. Using the double-quote notation you can directly use the values output by the  
  138. shell for example during a "scan" call.  
  139.   
  140. This HBase shell is the JRuby IRB with the above HBase-specific commands added.  
  141. For more on the HBase Shell, see <a href="http://wiki.apache.org/hadoop/Hbase/Shell">http://wiki.apache.org/hadoop/Hbase/Shell</a>  

 

Example case: 

 

1. 创建一张student表, ColumnFamily为name. 

Create 代码   收藏代码
  1. create 'student','name'  

 

2. 描述student表. 

Shell代码   收藏代码
  1. hbase(main):004:0> describe 'student'  
  2. DESCRIPTION                                                                                                        ENABLED  
  3.  {NAME => 'student', FAMILIES => [{NAME => 'name', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESSION => true  
  4.   'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}]  
  5.  }  
  6. 1 row(s) in 0.0710 seconds  
  7.   
  8. hbase(main):005:0>  

 

3. 往表student插入数据 

Shell代码   收藏代码
  1. hbase(main):017:0> put 'student','111','name:firstname','kim'  
  2. 0 row(s) in 0.0380 seconds  

 

4. 查询student, 键为111的value 

Shell代码   收藏代码
  1. hbase(main):023:0> get 'student','111'  
  2. COLUMN                                        CELL  
  3.  name:firstname                               timestamp=1338877705167, value=kim  
  4. 1 row(s) in 0.0190 seconds  
  5.   
  6. hbase(main):024:0>  

 

5. 全部查询 

Shell代码   收藏代码
  1. hbase(main):010:0> scan 'student'  
  2. ROW                                           COLUMN+CELL  
  3.  111                                          column=name:firstname, timestamp=1338877705167, value=kim  
  4. 1 row(s) in 0.4250 seconds  
  5.   
  6. hbase(main):011:0>  

  

6. 查询 

Shell代码   收藏代码
  1. hbase(main):019:0> get 'student','111',{COLUMN=>'name:firstname',VERSIONS=>10}  
  2. COLUMN                                        CELL  
  3.  name:firstname                               timestamp=1338877705167, value=kim  
  4. 1 row(s) in 0.0250 seconds  
  5.   
  6. hbase(main):020:0>  

 

7. 删除表 

Drop代码   收藏代码
  1. disable 'tablename'  
  2. drop 'tablename'  

猜你喜欢

转载自blog.csdn.net/wangshuminjava/article/details/80533023