HBase provides users with a convenient way to use the command line --HBase Shell.
HBase Shell provides most of HBase command, through HBase Shell, users can easily create, delete, and modify the table, you can also add data to the table, listed in the table of related information. This section describes some commonly used commands and the specific operation, and explains how to use the command line to achieve a "student achievement table."
Recommended Reading articles
Zero-based Big Data Quick Start Tutorial
web front-end development based tutorial
Big Data era need to know six things
Big Data framework hadoop Top 10 Myths
Experience big data development engineer salary 30K summary?
Big Data framework hadoop we encountered problems
- general operations
1. Query Server Status
hbase(main):0il:0>status
1 active master,0 backup masters, 1 servers,0 dead,4.0000 average load
2. Query the version number
hbase(main):012:0>version
1.2.1,r8d8a7107dc4ccbf36a92f64675dc60392f85c015,Wed Mar 30 11:19:21 CDT 2016
DDL operations
Data Definition Language (Data Defination Language, DDL) operation is mainly used to define the database schema, modify and query tables.
1. Create a table
hbase(main):013:0>
create’table’,’column_famaly’,’column_famaly1′,’column_famaly2′
0 row(s) in 94.9160 seconds
2. List all tables
hbase(main):014:0>list
TABLE
stu
table
test
3 row(s) in 0.0570 seconds
3. Get description of the table
hbase(main):015:0> describe’table’
Table table is ENABLED
table
COLUMN FAMILIES DESCRIPTION
{NAME =>’coluran_famaly’,DATA_BLOCK_ENCODING =>’NONE’,BLOOMFILTER =>’ROW’,REPLICATION_SCOPE=>’0′,VERSIONS=>’1′,COMPRESSION=>’NONE’, MIN_VERSIONS =>’0′,TTL=>’FOREVER’,KEEP_DELETED_CELLS=>’FALSE’,BLOCKSIZE=>’65536′,IN_MEMORY
=>’false’,BLOCKCACHE=>’true}
……
3 row(s) in 0.0430 seconds
4. Delete a column family
hbase(main):016:0>alter’table’,{NAME=>’column_famaly’,METHOD=>’delete’}
Updating all regions with the new schema…
1/1 regions updated.
Done.
0 row(s) in 3.0220 seconds
5. Delete a table
First, the table is set to disable.
hbase(main):020:0>disable’stu’
0 row(s) in 2.3150 seconds
Then delete a table.
hbase(main):021:0>drop’stu’
0 row(s) in 1.2820 seconds
6. query table exists
hbase(main):024:0>exists’table’
Table table does exist
0 row(s) in 0.0280 seconds
7. View the table is available
hbase(main):025:0>is_enabled’table’
true
0 row(s) in 0.0150 seconds
DML operations
DML (Data Manipulation Language, Data Manipulation Language) operations on the data table is mainly used to add, modify, retrieve, delete, and query.
1. Insert Data
Rw1 emp table to rows 3 columns are inserted.
hbase(main):031:0>put’emp’,’rw1′,’col_f1:name’,’tanggao’
0 row(s) in 0.0460 seconds
hbase(main):032:0>put’emp’,’rw1′,’col_f1:age’,’20’
0 row(s) in 0.0150 seconds
hbase(main):033:0>put’emp’,’rw1′,’col_f1:sex’,’boy’
0 row(s) in 0.0190 seconds
2. Get the data
Get all data rw1 lines emp table.
hbase(main):034:0> get ’emp’,’rw1′
COLUMN CELL
col_f1:age timestamp=1463055735107,value=20
col_f1:name timestamp=1463055709542,value=tanggao
col_f1:sex timestamp=1463055753395,value=boy
3 row(s) in 0.3200 seconds
All data acquisition emp table columns rw1 row col_f1 family.
hbase(main):035:0>get’emp’,’rw1′,’col_f1′
COLUMN CELL
col_f1:age timestamp=1463055735107,value=20
col_f1:name timestamp=1463055709542,value=tanggao col_f1:sex timestamp=1463055753395,value=boy
3 row(s) in 0.0270 seconds
3. Update a record
Rw1 update emp table row, column value col_f1 family age column.
hbase (main):037:0> put ’emp’,’rw1’col_f1:age’,’22’
0 row(s) in 0.0160 seconds
See the updated results.
hbase(main):038:0>get ’emp’,’rw1′,’col_f1:age’
COLUMN CELL
col_f1:age timestamp=1463055893492,value=22
1 row(s) in 0.0190 seconds
4. The two versions of the data acquisition time stamp
hbase(main):039:0>get ’emp’,’rw1′,{COLUMN=>’col_f1:age’,TIMESTAMP=>1463055735107}
COLUMN CELL
col_f1:age timestamp=1463055735107,value=20
1 row(s) in 0.0340 seconds
hbase(main):040:0>get ’emp’,’rw1′,{COLUMN=>’col_f1:age’,TIMESTAMP=>1463055893492}
COLUMN CELL
col_f1:age timestamp=1463055893492,value=22
1 row(s) in 0.0140 seconds
The full table scan
hbase(main):041:0>scan ’emp’
ROW COLUMN+CELL
id column=col_f1:age,timestamp=1463055893492,value=2
id column=col_f1:name,timestamp=1463055709542,value=tanggao
id column=col_f1:sex,timestamp=1463055753395,value=boy
1 row(s) in 0.1520 seconds
6. Delete an
To delete a column of the emp table rw1 row.
hbase(main):042:0>delete ’emp’,’rw1′,’col_f1:age’
0 row(s) in 0.0200 seconds
Check the delete operation results.
hbase(main):043:0>get ’emp’,’rw1′
COLUMN CELL
col_f1:name timestamp=1463.055709542,value=tanggao col_f1:sex timestamp=1463055753395,value=boy
2 row(s) in 0.2430 seconds
7. Delete all the cells in row
Use "deleteall" command to delete all the columns in the emp table rw1 row.
hbase(main) :044:0>deleteall ’emp’,’rw1′
0 row(s) in 0.0550 seconds
8. Number of rows in tables
hbase(main):045:0>count ’emp’
0 row(s) in 0.0450 seconds
9. Empty the entire table
hbase(main):007:0>truncate’emp’
Truncating ’emp’ table(it may take a while);
-Disabling table…
-Truncating table…
0 row(s) in 4.1510 seconds
HBase table example
The following example will be a "student transcript" to introduce the use of HBase commonly used commands.
Figure 1 is a student transcript, wherein, name is OK key, Grade column family is a special, and not only a name (the column below the column group is not the name), is a column family Course by three columns (Chinese, math and english). Users can create more columns in the course as needed, such as computing, physics and the like.
Figure 1 student transcripts
1. Create a table scores, a group comprising two columns: grade and course
hbase(main):001:0> create ‘scores’,’grade’,’course’
Table 2. Structure designed value added
put’scores’,’Jim1′,’grade:’1′
put’scores’,’Jim’,’course:Chinese’,’90’
put’scores’,’Jim’,’course:math’,’85’
put’scores’,’Jim’,’course:english’,’85’
put’scores’,’Tom’,’grade:’,’2′
put’scores’,’Tom’,’course:Chinese’,’97’
put’scores’,’Tom’,’course:math’,’100′
put’scores’,’Tom’,’course:english’,’92’
Table-like structure was built up, column family can freely add child inside the column. If no child under the column column families, only add ":" you can be.
The key to query data
Jim view the data line scores table.
hbase(main):012:0>get ‘scores’,’Jim’
View Jim scores table row, column family values course in math column.
hbase(main):012:0>get ‘scores’,’Jim’,’course:math’
Or with the following code.
hbase(main):012:0>get ‘scores’,’Jim’,{COLUMN=>’course:math’}
4. Scan all data
hbase(main):012:0>scan ‘scores’
The above command will display all rows of data, that is, all courses of Tom and Jim results, including chinese, math and english.
In order to limit the returned results, the user can specify the number of qualifiers, such as TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH or COLUMN.
Jim and Tom get english of results.
scan’scores’,{COLUMN=>’course:english’,STARTROW=>Jim,ENDROW=Tom}
5. Add a new column
Adding performance computing courses for Tom.
hbase(main):012:0>put’scores’,’Tom’,’course:computing’,’90’