Introducing 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:hbase(main):009:0> listTABLEcloudtable1 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 secondsThe 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+CELLrow1 column=cf:a, timestamp=1504866237162, value=value11 row(s) in 0.2420 secondsNote- 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.
- 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 CELLcf:a timestamp=1504866237162, value=value11 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 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 secondshbase(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