• Hbase操作命令



    1.创建新增表
    建表语句 create '表名','列簇名','列簇名'

    hbase shell> create 'mytable','ct','ct1' 

    语法:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
    新增或者覆盖数据 put '表名','键名','列名(不是列簇名)','值'
    指定的列名下单元格有值就覆盖..没有值就创建.所以HBase的添加数据和修改数据都是put语句..
    最后的时间戳可以不写..默认为系统时间,如果要写..切记不可使用引号括起来

    hbase shell> put 'mytable','woshikey','ct:msg','99999999999999'
    hbase shell> put 'mytable','woshikey','ct:msg','99999999999999',1462241148

    2.查询表
    列出所有表

    hbase shell> list 

    查看表结构

    hbase shell> describe 'mytable'

    扫描表
    语法: scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}

    hbase shell> scan 'mytable'

    返回所属列簇

    hbase shell> scan 'mytable',{COLUMNS=>'ct'}

    返回所属列簇里每个列的第一个值

    hbase shell> scan 'mytable',{COLUMNS=>'ct',LIMIT=>1} 

    返回所属列簇里指定列的第一个值

    hbase shell> scan 'mytable',{COLUMNS=>'ct:msg',LIMIT=>1}

    获取表数据
    语法: get <table>,<key>[,<columns
    主键过滤

    hbase shell> get 'mytable','rowkey1

    主键+列簇过滤

    hbase shell> get 'mytable','rowkey1','ct'

    主键+列簇+所属列过滤

    hbase shell> get 'mytable','rowkey1','ct:msg'

    主键+列簇过滤

    hbase shell> get 'mytable','rowkey1',{COLUMN=>'ct'}

    主键+列簇+所属列过滤

    hbase shell> get 'mytable','rowkey1',{COLUMN=>'ct:msg'}

    获取表行数
    语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
    INTERVAL设置多少行显示一次及对应的rowkey,默认1000;CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
    例如,查询表t1中的行数,每100条显示一次,缓存区为500

    hbase shell> count 'mytable', {INTERVAL => 100, CACHE => 500}

    3.删除表
    停用表

    hbase shell> disable 'mytable' 

    删除表

    hbase shell> drop 'table' 

    删除某个单元值的值会删除所有版本,必须指定列名
    语法:delete <table>, <rowkey>, <family:column> , <timestamp>
    测试后发现后边跟时间戳也没有用,依然会删除所有版本

    hbase shell> delete 'mytable','rowkey','ct:msg'

    删除行或者整个列簇
    可以不指定列名,删除整行数据
    语法:deleteall <table>, <rowkey>, <family:column> , <timestamp>

    hbase shell> deleteall 'mytable','ct'
    hbase shell> deleteall 'mytable'

    清空表数据
    语法: truncate <table>
    等同于 disable -> drop -> create

    hbase shell> truncate 'mytable'

    4.修改表
    修改表数据 put ‘表明’,‘主键’,‘列族:列名’,‘新值’

    put 't_user' ,'1001','st1:age','19'

    修改表的结构..删除某列簇
    删除表中的列簇 注: 要求先disable 表,,修改后enable表
    请严格区分大小写

    hbase shell> disable 'mytable'
    hbase shell> alter 'mytable',{NAME=>'ct',METHOD=>'delete'}
    hbase shell> enable 'mytable'

    修改表结构 新增一个列簇
    请严格区分大小写

    hbase shell> disable 'mytable'
    hbase shell> alter 'mytable',{NAME=>'columnsfamilyName',VERSIONS=>1}
    hbase shell> enable 'mytable'

    停用表

    hbase shell> disable 'mytable' 

    为表创建快照..这时还没有复制数据
    hbase shell> snapshot 'mytable', 'tableSnapshot'
    根据某个快照而创建新表..此时复制数据

    hbase shell> clone_snapshot 'tableSnapshot', 'newTableName' 

    删除快照

    hbase shell> delete_snapshot 'tableSnapshot' 

    删除原来的表

    hbase shell> drop 'mytable'
  • 相关阅读:
    记一次网易前端实习面试
    你知道吗?Web的26项基本概念和技术
    CSS 颜色代码大全
    研究旧项目, 常用 sql 语句
    Asp.net core 学习笔记 QR code and Barcode
    Html to PDF
    Asp.net core 学习笔记 Node Service
    Asp.net core Identity + identity server + angular + odata + 权限管理
    Angular Material (Components Cdk) 学习笔记 Table
    es6 getter setter
  • 原文地址:https://www.cnblogs.com/ypsy/p/9969448.html
Copyright © 2020-2023  润新知