hbase--client operation

1. Client

  • hbase
[root@node-01 hbase-1.2.0-cdh5.14.0]# hbase
Usage: hbase [<options>] <command> [<args>]

Commands:
Some commands take arguments. Pass no args or -h for usage.
  shell           Run the HBase shell
  hbck            Run the hbase 'fsck' tool
  snapshot        Create a new snapshot of a table
  snapshotinfo    Tool for dumping snapshot information
  wal             Write-ahead-log analyzer
  hfile           Store file analyzer
  zkcli           Run the ZooKeeper shell
  upgrade         Upgrade hbase
  master          Run an HBase HMaster node
  regionserver    Run an HBase HRegionServer node
  zookeeper       Run a Zookeeper server
  rest            Run an HBase REST server
  thrift          Run the HBase Thrift server
  thrift2         Run the HBase Thrift2 server
  clean           Run the HBase clean up script
  classpath       Dump hbase CLASSPATH
  mapredcp        Dump CLASSPATH entries required by mapreduce
  pe              Run PerformanceEvaluation
  ltt             Run LoadTestTool
  version         Print the version
  CLASSNAME       Run the class named CLASSNAME
  • hbase shell
    • Run the client command line of hbase
    • Exit: exit
    • Note one
      • Does not support SQL statements
      • Does not support SQL statements
      • Does not support SQL statements
      • Command cannot end with a semicolon
      • Command cannot end with a semicolon
      • Command cannot end with a semicolon
    • View command help documentation
      • HBase Shell; enter ‘help’ for list of supported commands.
      • help
    • Note two
      • If this command line is written incorrectly, you cannot delete it directly by pressing the backspace button
      • The default deletion is to delete backwards
      • Hold down ctrl+backspace delete key to delete forward (or 设置会话选项里的映射键,打两个√)

2 、 DDL

NameSpace management

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
  • If you don’t know the usage of a certain command
help 'command'
help 'create_namespace'

create

  • grammar
    • create_namespace ‘ns1’
  • test
    • create_namespace'hanjiaxiaozhi01'
    • create_namespace'hanjiaxiaozhi02'
    • create_namespace ‘student’

Enumerate

list_namespace

delete

drop_namespace 'hanjiaxiaozhi02'
  • List all tables in a namespace
    Insert picture description here

Table management

Group name: ddl
  Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters
  • The meaning of abbreviations in official documents
    • ns:namespace
    • t:table
    • r:rowkey
    • f: column family
    • c: column
    • v: value
    • ts: timestamp

create

  • Must specify in which namespace to create the table, if not specified, it will be created in the default namespace by default
  • The name of the table must be specified
  • At least one column family must be created
  • 方式一:直接给定列族的名称,不需要配置列族的属性
create 'ns1:t1', 'f1'
create 'ns1:t1', 'f1','f2'
  • test
create 'hanjiaxiaozhi01:hanjiaxiaozhi','cf1'
create 'heima' ,'cf1','cf2'
  • Without adding ns, it means operating default ns
  • 方式二:需要更改列族的属性
create 'ns1:t1', {
    
    NAME => 'f1', VERSIONS => 5}
  • test
create 'student:stu3',{
    
    NAME=>'basic',VERSIONS=>3},'other'

Enumerate

  • list

delete

  • grammar
drop  'nsname:tbname'
  • test
drop  'heima'
  • note
    • All tables in Hbase have two states
    • ENABLED startup state: a table that can be read and written normally
    • Disable disabled state: can not read and write
  • Need to modify or delete the Hbase table, you must first disable it
    • In order to avoid that someone is using this table, and sudden changes lead to inconsistencies
    • After the modification is successful, you need to re-enable the table before this table can be used
  • test
disable 'heima'
drop 'heima'
  • Enable table
enable 'ns:tbname'
  • Disable table
disable 'ns:tbname'
  • description
desc 'hanjiaxiaozhi01:hanjiaxiaozhi'

{
    
    NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 
desc 'heima'
                                                        
{
    
    NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}               
{
    
    NAME => 'cf2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}               
desc 'student:stu'
                                                                 
{
    
    NAME => 'basic', BLOOMFILTER => 'ROW', VERSIONS => '3', IN_MEMORY => 'false', KEEP_DELETED_CEL
LS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERS
IONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}             
{
    
    NAME => 'other', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CEL
LS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERS
IONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}             
2 row(s) in 0.2280 seconds

3. DML [Add, delete, modify, and check]

Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

put: insert data/update data [similar to replace in mysql, insert if it does not exist, update if it exists]

  • Function: Insert a column for a row of the Hbase table
  • grammar
put 'ns1:t1', 'r1', 'c1', 'value'
put 't1', 'r1', 'c1', 'value', ts1
  • test
put 'student:stu','20200101_001','basic:name','laoda'
put 'student:stu','20200101_001','basic:age',18
put 'student:stu','20200101_001','basic:sex','male'
put 'student:stu','20200101_001','other:phone','110'
put 'student:stu','20200101_001','other:addr','shanghai'

put 'student:stu','20200103_002','basic:name','laoer'
put 'student:stu','20200103_002','basic:age',20
put 'student:stu','20200103_002','other:phone','119'

put 'student:stu','20200102_003','basic:name','laosan'
put 'student:stu','20200102_003','other:phone','120'
put 'student:stu','20200102_003','other:addr','beijing'
  • Update
put 'student:stu','20200103_002','basic:name','laosi'
scan 'student:stu',{
    
    VERSIONS=>10}

get: Get data

  • Function: Return all data of one rowkey at most
  • The fastest way to query
  • Why: rowkey must be specified, rowkey is the index of the underlying Hbase
  • grammar
get 'ns1:t1', 'r1'
get 'ns1:t1', 'r1','c1'
  • test
get 'student:stu','20200103_002'
get 'student:stu','20200103_002','basic'
get 'student:stu','20200103_002','basic:name'

delete: delete data

  • Function: delete a certain column or a certain version of the data
  • grammar
delete 'ns1:t1', 'r1', 'c1', ts1
  • test
delete 'student:stu','20200102_003','other:phone'

scan: scan data

  • Usage 1: scan'ns:tbname'
    • Scan the entire table
scan 'student:stu'
  • Usage 2: scan'ns:tbname' + filter
    • Filter query

Guess you like

Origin blog.csdn.net/qq_46893497/article/details/114190140