HBase Shell is an interactive command-line interface for managing data in ApsaraDB for HBase. Use it to create and configure tables, insert and query data, and delete tables.
Prerequisites
Before you begin, ensure that you have:
An ApsaraDB for HBase instance (Standard Edition or Performance-enhanced Edition)
Shell access to the instance node
For connection setup, see:
Standard Edition: Use HBase Shell to access ApsaraDB for HBase Standard Edition clusters
Performance-enhanced Edition: Use HBaseue Shell to access an ApsaraDB for HBase Performance-enhanced Edition instance
Start and exit HBase Shell
Start HBase Shell from the instance node:
$ bin/hbase shell
hbase(main):001:0>To view available commands and usage, run:
hbase(main):001:0> helpTo exit, run:
hbase(main):001:0> quitCommand reference
HBase Shell supports two categories of commands. For the full command reference, see The Apache HBase Shell.
Data definition language (DDL)
| Command | Description |
|---|---|
create | Creates a table |
list | Lists all tables |
describe | Shows table details and configuration |
alter | Modifies a table or column family |
exists | Checks whether a table exists |
disable | Disables a table |
is_disabled | Checks whether a table is disabled |
enable | Enables a table |
is_enabled | Checks whether a table is enabled |
drop | Deletes a table |
Data manipulation language (DML)
| Command | Description |
|---|---|
put | Writes a value to a cell in a specified row and column |
get | Reads a single row or cell |
scan | Scans a table and returns multiple rows |
count | Counts the rows in a table |
delete | Deletes a specific cell value |
deleteall | Deletes all cells in a row |
truncate | Clears all data in a table by disabling, dropping, and re-creating it. Regions are not preserved. |
truncate_preserve | Clears all data in a table by disabling, dropping, and re-creating it. Regions from the original table are preserved. |
Basic operations
Create a table
Use create with the table name and at least one column family name:
hbase(main):001:0> create 'test', 'cf'List tables
hbase(main):003:0> listFilter by name or regular expression:
hbase(main):004:0> list 'abc.*'
hbase(main):005:0> list 'test'Insert data
Use put to write a value. Each put targets a specific table, row key, column (in family:qualifier format), and value:
hbase(main):006:0> put 'test', 'row1', 'cf:a', 'value1'
hbase(main):007:0> put 'test', 'row2', 'cf:b', 'value2'
hbase(main):008:0> put 'test', 'row3', 'cf:c', 'value3'Scan a table
scan returns all rows in a table:
hbase(main):009:0> scan 'test'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1421762485768, value=value1
row2 column=cf:b, timestamp=1421762491785, value=value2
row3 column=cf:c, timestamp=1421762496210, value=value3
3 row(s) in 0.0230 secondsFor single-row lookups, use get instead — it is faster than scan for retrieving individual records.
Read a single row
hbase(main):010:0> get 'test', 'row1'
COLUMN CELL
cf:a timestamp=1421762485768, value=value1
1 row(s) in 0.0350 secondsDisable and enable a table
Disable a table before deleting it or changing its settings:
hbase(main):012:0> disable 'test'
hbase(main):013:0> enable 'test'Delete a table
A table must be disabled before you can drop it:
hbase(main):014:0> disable 'test'
hbase(main):015:0> drop 'test'drop permanently deletes the table and all its data. This action cannot be undone.
Configure tables with alter
Use alter to modify column family settings on an existing table.
Set the major compaction period
The major compaction period is measured in milliseconds. The default is 7 days. Set to 0 to disable scheduled major compactions.
hbase(main):001:0> alter 'test', CONFIGURATION => {'hbase.hregion.majorcompaction' => 300000}Avoid changing this setting unless your workload specifically requires it.
Set data compression
For details on supported compression formats, see Data compression and encoding.
hbase(main):002:0> alter 'test', NAME => 'cf', COMPRESSION => 'SNAPPY'Set block encoding
hbase(main):003:0> alter 'test', NAME => 'cf', DATA_BLOCK_ENCODING => 'DIFF'Set the time to live (TTL)
TTL is measured in seconds. Data older than the TTL is automatically deleted. The following example sets a 30-day TTL (2,592,000 seconds):
hbase(main):004:0> alter 'test', NAME => 'cf', TTL => 2592000Pre-split a table into regions
Pre-splitting distributes data evenly across regions from the start. See Pre-split.