hbase常用操作命令

前言
  • 以下命令在hbase1.2.1版本下试验通过。
  • 记录常用hbase命令提高工作效率。
常用命令
  • 使用命令操作时,需要对表名列名带上单引号,否则会被hbase认为是一个变量,会报如下错误:

    NameError: undefined local variable or method `main2' for #<Object:0x44b21f9f>
    
  • 查看安装版本

    version
    
  • 列族相关

    1)增加/修改 一个列族,指定版本号
    alter 'test_tianyan', NAME => 'main2', VERSIONS => 6
    或者
    alter 'test_tianyan', { NAME => 'main2', VERSIONS => 6 }
    
    2)删除列族
    alter 'test_tianyan','delete'=>'main2' 
    
    3)如果是创建表时,则可以指定多个列族
    create 'new_table','f1','f2','f3'
    
    4)修改一个列族为多个版本
    默认情况下,hbase只会存储一个版本的数据,如果有获取多个版本值的情况,则可通过如下命令修改。
    alter 'test_tianyan',{NAME=>'main',VERSIONS=>5}
    
    4)创建表(数据7天过期)
    create 'YK.VVCOUNT_VIDEO_REAL_VV', {NAME => 'v', TTL => '604800'}
      
    注意NAME和VERSIONS必须是大写。
    可以使用VERSIONS和COLUMN指定获取多个版本数据。
    get 'test_tianyan','testRowKey1',{COLUMN=>'main:id',VERSIONS=>5}
    
  • 表结构相关

    1)查看表描述(desc命令是 describe的缩写)
    desc 'order_info_tbl'
    或者 describe 'order_info_tbl'
    
    2)删除表,在删除表之前,需要先disable,然后再用drop删除 
    disable 'order_info_tbl'
    drop 'order_info_tbl'
    
    3)删除并重建表(其实也是调用disable后使用drop删除的)
    truncate 'order_info_tbl'
    
  • 数据相关

    取5行数据
    scan 'order_info_tbl' ,{LIMIT=>5}
    
    查看hbase所有的filters
    show_filters
    
    列出所有表
    list
    列出sence开头的表
    list 'list 'sence.*' 
    
    通过rowKey精确查询 
    get 'order_info_tbl','1018112285488692_1542878164726_10'
    
    
    删除main列族下的tx_id列(delete '表名','rowKey','列族名:列' )
    delete 'order_info_tbl','1543071151193','main:tx_id'
    
    删除rowKey下的所有列
    deleteall 'order_info_tbl', ’rowkey'
    
    修改操作,将main列族下的tx_id列置空(put '表名','rowKey','列族名:列' )
    put 'order_info_tbl','1543071151193','main:tx_id',''
    
    
    设置指定rowKey下列的值
    put 'test_tianyan','row2','main:name','hyq'
    
    获取rowKey下具体一列的值
    get 'test_tianyan','row2',{COLUMN=>'main:name'}
    
    扫描某个列族下某列内容
    scan 'tache_2i2c_carddatas',{COLUMNS=>['main:provOrderId'],LIMIT=>10}
    
    
    
    查询列名以d开头,值带 “-”号的数据
    count 'process_2i2c_openuser', FILTER=>"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))"
    
    scan 'process_2i2c_openuser', FILTER=>"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))"
    
    scan 'process_2i2c_openuser', {FILTER=>"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))",LIMIT=>2224,REVERSED => TRUE}
    
    scan 'process_2i2c_openuser', {FILTER=>"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))",LIMIT=>10,REVERSED => TRUE}
    
    
    
    
    echo "scan 'process_2i2c_openuser', {FILTER=>\"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))\",LIMIT=>2224,REVERSED => TRUE}" | bin/hbase shell > 1.txt
    
    倒序输出scan结果到文件中
    echo "scan 'process_2i2c_openuser', {FILTER=>\"ColumnPrefixFilter('d') AND ( ValueFilter(=,'substring:-'))\",REVERSED => TRUE}" | bin/hbase shell > 1.txt
    
    输出scan结果到文件方法2:
    hbase shell <<EOF >myText
    scan 'foo'
    EOF
    
    方法3:
    $ hbase shell <<< "scan 'sometable'" > myoutput.txt
    
  • scan高级用法

    配合show_filters命令,指定相应的filter使用。
    
    指定开始位置和结束位置
    scan 'order_info_tbl',{STARTROW=>'1018112552468133',ENDROW=>'1018112658271187',LIMIT=>11}
    
    模糊匹配rowKey
    scan 'test_tianyan',{ROWPREFIXFILTER=>'r',LIMIT=>2}
    
    扫描多个列,限制行数
    scan 'test_tianyan',{COLUMNS=>['main:id','main:name'],LIMIT=>1}
    
    模糊匹配rowKey
    scan 'order_info_tbl',{ROWPREFIXFILTER =>'11',LIMIT=>2,FILTER=>"(QualifierFilter (>, 'binary:1018021991552673')) "}
    
    过滤出10条包含指定值的列
    scan 'order_info_tbl', {FILTER=>"ValueFilter(=,'substring:41012_11')",LIMIT=>10}
    
    rowKey前缀模糊匹配
    scan 'test_tianyan', {FILTER => "PrefixFilter('r')"}
    
    rowKey前缀模糊匹配,只查询指定列
    scan 'test_tianyan',{COLUMNS=>'main:name',FILTER=>"PrefixFilter('r')"}
    scan 'test_tianyan',{COLUMNS=>['main:name','main:id'],FILTER=>"PrefixFilter('r')"}
    
    列过滤
    scan 'test_tianyan',{FILTER=>"QualifierFilter(>=,'binary:name')"}
    
    时间过滤器
    scan 'test_tianyan',{FILTER=>"TimestampsFilter(1543813062349,1543813090552)"}
    
其他技巧
  • 组合多个命令
    可以组合多个命令,执行不同的操作,例如:改变列族main2的版本号为4,删除main4列族
    alter 'test_tianyan',{NAME=>'main2',VERSIONS=>4},{NAME=>'main4',METHOD=>'delete'}
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值