Updated on 2024-04-29 GMT+08:00

Introducing HBase Shell Commands

This section describes common HBase shell commands.

  1. Start the HBase shell.

    Go to the HBase directory and run the following command to access the HBase shell:

    ./bin/hbase shell
  2. Get help information.

    After you run the help command in the HBase shell, all command information as well as common command instructions and use methods will be returned.

    hbase(main):001:0> help
  3. Create a table.

    Run the create command to create a table. When creating a table, you must specify the table name and column family name.

    hbase(main):007:0> create 'cloudtable','cf'
    0 row(s) in 1.5530 seconds
    
    => Hbase::Table - cloudtable
  4. Query a table:

    Run the list command to query the specified table. The table name must be specified.

    hbase(main):009:0> list 'cloudtable'
    TABLE
    cloudtable
    1 row(s) in 0.0060 seconds
    
    => ["cloudtable"]
  5. Insert a piece of record to a table.

    Run the put command to insert a piece of record to the specified table. You need to specify the table name, primary key, customized column, and inserted value.

    hbase(main):004:0> put 'cloudtable','row1','cf:a','value1'
    0 row(s) in 0.2720 seconds

    The following describes parameters in the command:

    • cloudtable: table name
    • row1: primary key
    • cf:a: customized column
    • value1: inserted value
  6. Scan records

    Run the scan command to scan a table. You need to specify the table name and you can scan a full table or specify a scanning range.

    hbase(main):001:0> scan 'cloudtable'
    ROW                                                                  COLUMN+CELL
    row1                                                                column=cf:a, timestamp=1504866237162, value=value1
    1 row(s) in 0.2420 seconds
    • If the TTL of the cell is set when the data is inserted, the TTL attribute cannot be viewed. You can check whether the TTL configuration is successful.
    • If the TTL of the cell is not set when data is inserted, the system automatically inserts the current time as the timestamp.
  7. Query a single record.

    Run the get command to query a single record. The name and primary key of the queried table must be specified.

    hbase(main):001:0> get 'cloudtable','row1'
    COLUMN                                                               CELL
    cf:a                                                                timestamp=1504866237162, value=value1
    1 row(s) in 0.2280 seconds
  8. Disable a table.

    Before modifying or deleting a table, you need to disable the table. Run the disable command to disable the table. When you perform operations on a disabled table, "ERROR" will be reported, indicating that the table is disabled.

    hbase(main):002:0> disable 'cloudtable'
    0 row(s) in 2.3550 seconds
  9. Enable a table.

    If you want to use a table that has been disabled, run the enable command to enable the table.

    hbase(main):004:0> enable 'cloudtable'
    0 row(s) in 1.2500 seconds
  10. Delete a table.

    Run the drop command to delete a table that you do not require anymore. Before deleting a table, disable the table. Otherwise, "ERROR" will be displayed, indicating that the table is enabled. Deleting a table will cause data loss. Therefore, exercise caution when deleting a table.

    hbase(main):007:0> disable 'cloudtable'
    0 row(s) in 2.2380 seconds
    
    hbase(main):008:0> drop 'cloudtable'
    0 row(s) in 1.2600 seconds
  11. Exit the HBase shell.

    Run the quit command to exit the HBase shell.

    hbase(main):009:0> quit