After you create an HBase cluster, you can use HBase Shell to connect to HBase and perform operations such as reading and writing data. This topic describes how to use HBase Shell to connect to HBase. This topic also describes some common HBase Shell commands.

Prerequisites

A DataServing cluster is created. For more information, see Create a cluster.

Connect to HBase

  1. Log on to the DataServing cluster in SSH mode. For more information, see Log on to a cluster.
  2. Run the following command to connect to HBase:
    hbase shell

    After you connect to HBase, the system displays some basic usage tips, the HBase version information, and the hbase(main):001:0> prompt.

    You can run the help command to view the list of commands supported by HBase Shell.

Common HBase Shell commands

Create a table

Run the create command to create a table. You need to specify the table name and one or more column families. For example, run the following command to create a table named table1 that contains a column family named cf1:
create 'table1', 'cf1'

Write data to a table

Run the put command to write data to a table. You need to specify the table name, one or more rows, one or more columns, and values to be written. A column in HBase consists of a column family and a column qualifier, which are separated by a colon (:). In the following example, column cf1:q1 consists of column family cf1 and column qualifier q1.
put 'table1', 'r1', 'cf1:q1', 'v1'
put 'table1', 'r1', 'cf1:q2', 'v2'
put 'table1', 'r2', 'cf1:q1', 'v3'

Scan a table

Run the scan command to obtain all data that meets the specified conditions from a table. You can add conditions to the scan command based on your business requirements. For example, run the following command to obtain all data in column cf1:q1 of table table1:
scan 'table1', {COLUMNS => 'cf1:q1'}
The following output is returned:
ROW                                                COLUMN+CELL
 r1                                                column=cf1:q1, timestamp=2022-09-14T16:06:34.339, value=v1
 r2                                                column=cf1:q1, timestamp=2022-09-14T16:06:36.615, value=v3
2 row(s)

Obtain data

Run the get command to obtain data of a single row or cell from a table. You can add conditions to the get command based on your business requirements. For example, run the following command to obtain the value of column cf1:q1 in row r1 of table table1:
get 'table1', 'r1', {COLUMNS => 'cf1:q1'}
The following output is returned:
COLUMN                                             CELL
 cf1:q1                                            timestamp=2022-09-14T16:06:34.339, value=v1
1 row(s)

Delete data

  • Delete data of a single cell
    Run the delete command to delete the value of a single cell from a table. A cell corresponds to a column in a row of a table. For example, run the following command to delete the value of column cf1:q1 in row r2 of table table1:
    delete 'table1', 'r2', 'cf1:q1'
  • Delete data of multiple cells
    Run the deleteall command to delete the values of all columns that meet the specified conditions in a row of a table. For example, run the following command to delete all data in row r1 of table table1. You can add column family names to the command to limit the scope of deletion.
    deleteall 'table1', 'r1'

Disable a table

Run the disable command to disable a table. Before you delete a table or modify some settings of a table, you must disable the table. For example, run the following command to disable table table1:
disable 'table1'

Enable a table

Run the enable command to enable a table. For example, run the following command to enable table table1:
enable 'table1'

Delete a table

Run the drop command to delete a table. You must disable a table before you delete the table. For example, run the following command to delete table table1:
drop 'table1'

References

For more information, see Apache HBaseâ„¢ Reference Guide on the official website of Apache HBase.