After you create an E-MapReduce (EMR) cluster that contains the HBase service, 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 and use common HBase Shell commands.
Prerequisites
A DataServing cluster or custom cluster that contains the HBase service is created. For more information, see Create a cluster.
Connect to HBase
Log on to the desired cluster in SSH mode. For more information, see Log on to a cluster.
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 must specify the table name and one or more column families. For example, you can 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 must specify a table name, a row key, a column, and a value to be written. A column in HBase consists of a column family and a column qualifier. In the following example, the cf1:q1 column consists of the 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, you can run the following command to obtain all data in the cf1:q1 column of 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, you can run the following command to obtain the value of the cf1:q1 column in the r1 row of 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, you can run the following command to delete the value of the cf1:q1 column in the r2 row of 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, you can run the following command to delete all data in the r1 row of 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 specific settings of a table, you must disable the table. For example, you can run the following command to disable table1:
disable 'table1'
Enable a table
Run the enable
command to enable a table. For example, you can run the following command to enable table1:
enable 'table1'
Drop a table
Run the drop
command to drop a table. You must disable a table before you drop the table. For example, you can run the following command to drop table1:
drop 'table1'
References
For more information, see Apache HBase Reference Guide on the official website of Apache HBase.