hbase command combing

The following commands are based on the hbase version:

hbase(main):041:0> version
1.2.0-cdh5.7.1, rUnknown, Wed Jun  1 16:30:06 PDT 2016
  •  

general

status: View hbase status

hbase(main):002:0> status
1 active master, 1 backup masters, 4 servers, 0 dead, 0.5000 average load

table_help: simple entry to table operation

t = create 't','cf'  
t = get_table 't'
t.put 'r1','cf:q','v'
t.scan
t.disable
t.enable
t.flush
t.disable
t.drop

whoami: View current users and groups

hbase(main):252:0* whoami
chengguoqiang (auth:SIMPLE)
    groups: chengguoqiang, wheel

ddl operation

  • list View list of tables
  • create Create table
  • exists Check whether the table exists
  • describe / desc view table structure
  • enable / enable_all / is_enabled table is available for production, judge whether production is available
  • disable / disable_all / is_disabled Disable table, determine whether to disable
  • drop / drop_all delete table
  • get_table Get an instance
  • locate_region returns the region, new hbase command
  • show_filters has no use for the time being
  • Alter modifies the table structure, the hbase.online.schema.update.enable parameter determines whether it can be modified in production
  • alter_async asynchronously modify the table structure
hbase(main):088:0* exists 't'
hbase(main):089:0> desc 't'
hbase(main):090:0> alter 't',{NAME=>'cf', VERSIONS=>'5'}, {NAME=>'cf1', VERSIONS=>'3', COMPRESSION=>'GZ',TTL=>'86400',IN_MEMORY=>'true'}
hbase(main):092:0> alter_status 't'

When creating a table, hbase assigns a region to the table by default. All read and write requests will access the same region of the regionServer. At this time, the effect of load balancing cannot be achieved, and other regionServers in the cluster may be relatively idle. status. To solve this problem, you can use pre-splitting, which is configured when the table is created to generate multiple regions. Hbase comes with two pre-split algorithms,  HexStringSplit  and UniformSplit  . If our row key is a hexadecimal string as a prefix, it is more suitable to use HexStringSplit as a pre-split algorithm . For example, we use HexHash (prefix) as the prefix of the row key, where Hexhash is the hash algorithm that finally gets the hexadecimal string. We can also use our own split algorithm.

create 'profile:test','data',{NUMREGIONS => 4, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 1}
  •  

namespace

  • list_namespace Namespace list
  • create_namespace Create a namespace
  • describe_namespace Namespace description
  • list_namespace_tables View tables in the specified namespace
  • alter_namespace modify or add namespace attributes
  • drop_namespace delete the namespace, it must be an empty namespace
hbase(main):028:0> create_namespace 'profile'
hbase(main):029:0> list_namespace 'profile'
hbase(main):036:0* alter_namespace 'profile',{METHOD=>'set', 'TEST_PROPERTY'=>'TEST_VALUE'}
hbase(main):030:0> describe_namespace 'profile'

dml

  • put insert a record
  • append Put if the record does not exist, append value if it exists
  • get Get a record
  • scan scan record
  • count Get the number
  • delete delete rowkey, column must be specified
  • deleteall delete the entire rowkey
  • incr counter, insert a record, add 1 if it exists
  • get_counter returns the counter value
  • truncate empty table
  • truncate_preserve clears the table, but saves the partition information
  • get_splits returns a list of partitions
hbase(main):005:0> put 't','r1','cf1:q1','v1',{ATTRIBUTES=>{'att1'=>'val1'}}
hbase(main):006:0> scan 't'
hbase(main):007:0> get 't','r1',{COLUMN => 'cf1'}
hbase(main):042:0* put 't','r2','cf1:q2','v2',{ATTRIBUTES=>{'att1'=>'val1'}}

hbase(main):043:0> put 't','r3','cf1:q2','v3',{ATTRIBUTES=>{'att1'=>'val1'}}

hbase(main):044:0> put 't','r5','cf1:q5','v5',{ATTRIBUTES=>{'att1'=>'val1'}}`
hbase(main):045:0> put 't','r11','cf1:q11','v11',{ATTRIBUTES=>{'att1'=>'val1'}}
hbase(main):046:0> put 't','r8','cf1:q8','v8',{ATTRIBUTES=>{'att1'=>'val1'}}
scan 't',{COLUMN=>'cf1',LIMIT=>5, STARTROW=>'r2', ENDROW=>'r5'}
hbase(main):059:0* delete 't','r5','cf1:q5'
hbase(main):076:0* count 't'
hbase(main):051:0> incr 't','r2','cf1:q5'
hbase(main):053:0> get_counter 't','r2','cf1:q5'

hbase(main):105:0> create 'profile:t1','cf1',{SPLITS=>['a','b','c']}
hbase(main):105:0> get_split 'profile:t1'

security

  • grant authorization, can be refined to column
  • revoke cancel authorization
  • user_permission View table open permissions

    READ(‘R’), WRITE(‘W’), EXEC(‘X’), CREATE(‘C’), ADMIN(‘A’)

// Syntax : grant <user> <permissions> [<@namespace> [<table> [<column family> [<column qualifier>]]]
grant 'chengguoqiang','RW', 'profile:yingyun'

// Syntax : user_permission <table>
user_permission 'profile:yingyun'


// Syntax : revoke <user> [<table> [<column family> [<column qualifier>]]
revoke 'chengguoqiang','profile:yingyun'

Reprinted from: https://blog.csdn.net/baidu_35482842/article/details/51803639

Guess you like

Origin blog.csdn.net/xiezhen_zheng/article/details/82458237