HBase Shell Commands
This section describes common HBase shell commands. For more HBase shell commands, visit https://learnhbase.wordpress.com/2013/03/02/hbase-shell-commands/.
- Start the HBase shell.
Go to the HBase directory and run the following command to access the HBase shell:
./bin/hbase shell
- 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
- 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
- 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"]
- 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
- 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
- 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
- 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
- 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
- Delete a table.
Run the drop command to delete a table that you do not require any more. 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
- Exit the HBase shell.
Run the quit command to exit the HBase shell.
hbase(main):009:0> quit
Last Article: Using HBase Shell to Access a Cluster
Next Article: Accessing the HBase Web UI
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.