hbase操作命令

Posted 海绵不老

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hbase操作命令相关的知识,希望对你有一定的参考价值。

hbase操作命令

增删表、增删域名空间、修改表的属性

进入hbase客户端:

   [atguigu@hadoop1 hbase-1.3.1]$ hbase shell
	SLF4J: Class path contains multiple SLF4J bindings.
	SLF4J: Found binding in [jar:file:/opt/module/hbase-1.3.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
	SLF4J: Found binding in [jar:file:/opt/module/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12- 1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
	SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
	SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
	HBase Shell; enter 'help<RETURN>' for list of supported commands.
	Type "exit<RETURN>" to leave the HBase Shell
	Version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017
	
	hbase(main):001:0> 

查看域名空间:

     hbase(main):004:0> list_namespace
     NAMESPACE                                                                                                                                                                                 
     default                                                                                                                                                                                   
     hbase                                                                                                                                                                                     
     2 row(s) in 0.6110 seconds

查看域名属性信息:

      hbase(main):002:0> describe_namespace 'hbase'
	  DESCRIPTION                                                                                                                                                                               
	  NAME => 'hbase'                                                                                                                                                                         
	   1 row(s) in 0.3100 seconds

查看域名空间中的所有表:

	hbase(main):001:0> list_namespace_tables 'hbase'
	TABLE                                                                                                                                                                                     
	meta                                                                                                                                                                                      
	namespace                                                                                                                                                                                 
	2 row(s) in 0.3150 seconds

创建域名空间:

 hbase(main):001:0> create_namespace 'ns1'

创建表:

	hbase(main):001:0> create 'ns1:t1','cf1','cf2'
	0 row(s) in 2.6770 seconds

     => Hbase::Table - ns1:t1

查看表:

   hbase(main):002:0> describe 'ns1:t1'
   Table ns1:t1 is ENABLED                                                                                                                                                                   
	ns1:t1                                                                                                                                                                                    
	COLUMN FAMILIES DESCRIPTION                                                                                                                                                               
	NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VE
	RSIONS => '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_VE
	RSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'                                                                                                      
	2 row(s) in 0.1680 seconds

查看表存不存在:

   hbase(main):001:0> exists 'ns1:t1'
  Table ns1:t1 does exist                                                                                                                                                                   
   0 row(s) in 0.5300 seconds

查看表是否启用状态(只有启用状态才能进行 写操作):

  hbase(main):001:0> is_enabled 'ns1:t1'
  true                                                                                                                                                                                      
  0 row(s) in 0.5660 seconds
  同理:is_disabled 'ns1:t1'

停用表:

    hbase(main):001:0> disable 'ns1:t1'
启用表:

    hbase(main):001:0> enable 'ns1:t1'

 统计表有多少行:
    
    hbase(main):001:0> count 'ns1:t1'

清空表:

     hbase(main):001:0> truncate 'ns1:t1'

查看表切分了几个Region:
   
     hbase(main):001:0> get_spilts 'ns1:t1'

 给表增加列族:
      
      hbase(main):001:0> alter 'ns1:t1',NAME => 'f3'

 更新表的列的属性:
 
    hbase(main):001:0> alter 'ns1:t1',NAME => ‘f3’,VERSIONS => 3
  删库(只有改库下的所有表都删除才能删库):
   
     hbase(main):001:0> drop_namespace 'ns1:f1'
 删表(只有改表是disable状态才能删):
 
      hbase(main):001:0> drop 'ns1:f1'

查询、插入、删除数据

插入一条数据(向第一行,列族cf1,插入一个列为name,值为jack的格子)

        hbase(main):001:0> put 't1','r1','cf1:name','jack'

查看某行的数据:

       hbase(main):001:0> get ‘t1’,'r1'

获取多行的数据:

         hbase(main):001:0> scan ‘t1’

删除某行的某个列族的一个列:

          hbase(main):001:0> delete 't1','r1','cf1:age'

查看所有的数据(10个版本以内,包含已删除的数据):

        hbase(main):001:0> scan 't1',RAW=>true,VERSIONS=>10	

插入一条数据(带时间戳

        hbase(main):001:0> put ‘t1’,'r1','cf1:age','10',1609758553072

查询多条数据,scan高级用法:

        hbase(main):001:0> scan 't1',COLUMNS=>['cf1:age'],LIMIT=>2,STARTROW=>'r2'
           

					hbase(main):001:0> scan 't1',COLUMNS=>['cf1:age'],LIMIT=>2,STARTROW=>'r2'
					ROW                                             COLUMN+CELL                                                                                                                               
					 r2                                             column=cf1:age, timestamp=1610199211843, value=10                                                                                         
					 r3                                             column=cf1:age, timestamp=1610199217132, value=10                                                                                         
					2 row(s) in 0.5510 seconds
      
          hbase(main):001:0> scan 't1',COLUMNS=>['cf1:age'],STARTROW=>'r2',ENDROW=>'r5'
      
                    hbase(main):001:0>  scan 't1',COLUMNS=>['cf1:age'],STARTROW=>'r2',ENDROW=>'r5'
					ROW                                             COLUMN+CELL                                                                                                                               
					 r2                                             column=cf1:age, timestamp=1610199211843, value=10                                                                                         
					 r3                                             column=cf1:age, timestamp=1610199217132, value=10                                                                                         
					 r4                                             column=cf1:age, timestamp=1610199221386, value=10                                                                                         
					3 row(s) in 0.3860 seconds

查看hbase hfile文件信息:

	[atguigu@hadoop1 root]$ hbase org.apache.hadoop.hbase.io.hfile.HFile -e -p -f      hdfs://hadoop1:9000/HBase/data/default/t1/11e358e4d2913376c5c876e3cec500d6/cf1/aa1d5e75e5b64994ad02357bf1bdc2c0
	       SLF4J: Class path contains multiple SLF4J bindings.
	SLF4J: Found binding in [jar:file:/opt/module/hbase-1.3.1/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
	SLF4J: Found binding in [jar:file:/opt/module/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
	SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
	SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
	
	2021-01-09 22:45:03,773 INFO  [main] hfile.CacheConfig: Created cacheConfig: CacheConfig:disabled
	K: r1/cf1:age/1610199195951/Put/vlen=2/seqid=10 V: 10
	K: r2/cf1:age/1610199211843/Put/vlen=2/seqid=11 V: 10
	K: r3/cf1:age/1610199217132/Put/vlen=2/seqid=12 V: 10
	K: r4/cf1:age/1610199221386/Put/vlen=2/seqid=13 V: 10
	K: r5/cf1:age/1610199225843/Put/vlen=2/seqid=14 V: 10
	K: r6/cf1:age/1610199229831/Put/vlen=2/seqid=15 V: 10
	Scanned kv count -> 6

以上是关于hbase操作命令的主要内容,如果未能解决你的问题,请参考以下文章

Hbase常用操作命令

2021年大数据HBase:HBase的相关操作-客户端命令式!建议收藏

[Hbase]hbase命令行基本操作

hbase简单操作

hbase操作命令

hbase操作命令