Hbase common commands

1. Enter hbase shell console

$HBASE_HOME/bin/hbase shell

    If there is kerberos authentication, you need to use the corresponding keytab for authentication (using the kinit command) in advance. After the authentication is successful, you can enter the hbase shell and use the whoami command to view the current usage.

2. View all tables

hbase(main):001:0> list
TABLE                                                                                                                                           
OS_ORDER2                                                                                                                                       
qqq                                                                                                                                             
scores                                                                                                                                          
t1                                                                                                                                              
table2                                                                                                                                          
5 row(s) in 0.2270 seconds

=> ["OS_ORDER2", "qqq", "scores", "t1", "table2"]

 3. Create the table

#Table name is t1, family name is f1 and f2 version is 2                                                                                                                                          
hbase(main):002:0> create 't1',{NAME => 'f1', VERSIONS => 2},{NAME => 'f2', VERSIONS => 2}
0 row(s) in 1.4210 seconds

=> Hbase::Table - t1

 4. Delete the table

    Divided into two parts: 1) first disable

                      2) Then drop

hbase(main):004:0> disable 't1'
hbase(main):005:0> drop 't1'

 5. View the table structure

hbase(main):010:0> describe 't1'
Table t1 is ENABLED                                                                                                                             
t1                                                                                                                                              
COLUMN FAMILIES DESCRIPTION                                                                                                                     
{NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '2', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                   
{NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '2', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                   
2 row(s) in 0.0320 seconds

 6. Modify the table structure

    Modifying the table structure needs to disable first

hbase(main):002:0> disable 't1'
0 row(s) in 2.3620 seconds

hbase(main):003:0> alter 't1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 3.8080 seconds

hbase(main):004:0> enable 't1'
0 row(s) in 1.2520 seconds

 7. Assign permissions

 

# Syntax: grant <user> <permissions> <table> <column family> <column qualifier> Parameters are separated by commas
# Permissions are represented by five letters: "RWXCA".
# READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')
# For example, to assign read and write permissions to table t1 to user 'tr',
hbase(main)> grant 'trt','RW','t1'
 8. View permissions

 

# 语法:user_permission <table>
# For example, view the list of permissions for table t1
hbase(main)> user_permission 't1'

  

 9. Remove permissions

 

# Similar to assigning permissions, syntax: revoke <user> <table> <column family> <column qualifier>
# For example, revoke the privileges of tr user on table t1
hbase(main)> revoke 'tr','t1'

 

 10. Add data

 

 

# 语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
# For example: add a row to table t1: rowkey is rowkey001, family name: f1, column name: col1, value: value01, timestamp: system default

hbase(main)> put 't1','rowkey001','f1:col1','value01'
 

 

 11. Query data

      1) Query a row of data

 

# 语法:get <table>,<rowkey>,[<family:column>,....]
# For example: query table t1, the value of col1 under f1 in rowkey001
hbase(main)> get 't1','rowkey001', 'f1:col1'
# or:
hbase(main)> get 't1','rowkey001', {COLUMN=>'f1:col1'}
# Query table t1, all column values ​​under f1 in rowke002
hbase(main)> get 't1','rowkey001'
     2) Scan table
# 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
# Also, you can add advanced features like STARTROW, TIMERANGE, and FITLER
# For example: scan the first 5 data of table t1
hbase(main)> scan 't1',{LIMIT=>5}
     3) The number of rows of data in the query table
# 语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
# INTERVAL sets how many rows to display once and the corresponding rowkey, the default is 1000; the size of the cache area that CACHE fetches each time, the default is 10, adjusting this parameter can improve the query speed
# For example, the number of rows in the query table t1 is displayed every 100, and the buffer area is 500
hbase(main)> count 't1', {INTERVAL => 100, CACHE => 500}
 12. Deletion of data

 

    1) Delete the value of a column in a row

# Syntax: delete <table>, <rowkey>, <family:column> , <timestamp>, the column name must be specified
# For example: delete the data of f1:col1 in table t1, rowkey001
hbase(main)> delete 't1','rowkey001','f1:col1'

     2) delete a row of data

# Syntax: deleteall <table>, <rowkey>, <family:column> , <timestamp>, you can delete the entire row of data without specifying the column name
# For example: delete the data of table t1, rowk001
hbase(main)> deleteall 't1','rowkey001'

     3) Delete all the data in the table

# Syntax: truncate <table>
# The specific process is: disable table -> drop table -> create table
# For example: delete all data in table t1
hbase(main)> truncate 't1'

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326848962&siteId=291194637