HBase shell常用命令

1.进入Hbase shell命令

   $>hbase shell

2.建议参照”help”命令

3.shell命令

  –> create创建表命令:

      >create ‘table_name’,’baseinfo’,’address’  

      其中表名是table_name,列簇是baseinfo和address。

  –>put插入数据

      >put ‘table_name’,’row-1′,’baseinfo:name’,’zhangsan’

      >put ‘table_name’,’row-1′,’baseinfo:age’,’12’

      >put ‘table_name’,’row-1′,’baseinfo:sex’,’男’

      >put ‘table_name’,’row-1′,’address:city’,’北京’

        其中row-1是rowkey,列簇后面的是列,最后一个字段是value值

  –>scan扫描表

      >scan ‘table_name’

        输出全部table_name表的信息和数据

  –>get获取单条数据命令

      >get ‘table_name’,’row-1′

        其中table_name是表名,row-1是rowkey,得到的是row-1的全部数据

  –>delete删除记录命令

      >delete ‘table_name’,’row-1′,’baseinfo:name’

        其中table_name是表名,row-1是rowkey,baseinfo是列簇,name是列

  –>describe描述指令检索结构

      >desc ‘table_name’

  –>修改版本号

    默认版本是1

      >alter ‘table’,{NAME=>’baseinfo’,VERSION=>5}

  通过scan ‘表名’,{VERSION=>*}指令,检索当前表的数据版本

  执行delete删除指令时,如需按照ts(timestamp)时间戳进行删除操作时,之前版本一并删除掉

  –>drop删除table指令

    >disbale ‘ns1:tablename’  //首先要禁用table

    >drop ‘ns1:tablename’  //删除table

      其中ns1是命名空间

  –>get_table指令:将table映射成相对应的变量(table实例),通过table实例对表进行相关操作

    >t1 = get_table ‘table_name’

    >t1.scan

    >t1.put ‘row-2′,’baseinfo:name’,’zhangsan’

    >t1.get ‘row-2’

namespace名字空间,相当于传统数据库的表空间

  >create namespace ‘ns1’

  >describe_namespace ‘ns1’

balance负载均衡指令,需使用开关模式,原因是负载均衡比较耗费资源

  >balance_switch true  //开启负载均衡

  >balancer       //执行负载均衡

  >balance_switch false  //关闭负载均衡

  >balancer ‘force’    //强制负载均衡

 

4.meta元数据内容
——————————————-
1.使用scan扫描[hbase:meta]
  hbase(main):003:0> scan ‘hbase:meta’
  ROW                COLUMN+CELL
customer,,1533056364951.4e6032c76b column=info:regioninfo, timestamp=1533073783155, value={ENCODED => 4e6032c76b12fe55be487eadc40a70f0, NA
12fe55be487eadc40a70f0. ME => ‘customer,,1533056364951.4e6032c76b12fe55be487eadc40a70f0.’, STARTKEY => ”, ENDKEY => ”}
customer,,1533056364951.4e6032c76b column=info:seqnumDuringOpen, timestamp=1533073783155, value=\x00\x00\x00\x00\x00\x00\x00\x1E
12fe55be487eadc40a70f0.
customer,,1533056364951.4e6032c76b column=info:server, timestamp=1533073783155, value=master:16020
12fe55be487eadc40a70f0.
customer,,1533056364951.4e6032c76b column=info:serverstartcode, timestamp=1533073783155, value=1533069282809
12fe55be487eadc40a70f0.
hbase:namespace,,1532995591775.5a1 column=info:regioninfo, timestamp=1533073782978, value={ENCODED => 5a1c1a877777167a858f23905b72396e, NA
c1a877777167a858f23905b72396e. ME => ‘hbase:namespace,,1532995591775.5a1c1a877777167a858f23905b72396e.’, STARTKEY => ”, ENDKEY => ”}
hbase:namespace,,1532995591775.5a1 column=info:seqnumDuringOpen, timestamp=1533073782978, value=\x00\x00\x00\x00\x00\x00\x00\x1F
c1a877777167a858f23905b72396e.
hbase:namespace,,1532995591775.5a1 column=info:server, timestamp=1533073782978, value=master:16020
c1a877777167a858f23905b72396e.
hbase:namespace,,1532995591775.5a1 column=info:serverstartcode, timestamp=1533073782978, value=1533069282809
c1a877777167a858f23905b72396e.
ns1:student,,1533068816416.bfda8a0 column=info:regioninfo, timestamp=1533069385014, value={ENCODED => bfda8a08fdfccb4124b1a4e483f02b5b, NA
8fdfccb4124b1a4e483f02b5b. ME => ‘ns1:student,,1533068816416.bfda8a08fdfccb4124b1a4e483f02b5b.’, STARTKEY => ”, ENDKEY => ”}
ns1:student,,1533068816416.bfda8a0 column=info:seqnumDuringOpen, timestamp=1533069385014, value=\x00\x00\x00\x00\x00\x00\x00\x06
8fdfccb4124b1a4e483f02b5b.
ns1:student,,1533068816416.bfda8a0 column=info:server, timestamp=1533069385014, value=master:16020
8fdfccb4124b1a4e483f02b5b.
ns1:student,,1533068816416.bfda8a0 column=info:serverstartcode, timestamp=1533069385014, value=1533069282809
8fdfccb4124b1a4e483f02b5b.
  3 row(s) in 0.3440 seconds
    说明:regionname格式:
    <table_name>+”,”+<startKey>+”,”+<timestamp>+”.”+<ENCODED>MD5生成码(生成规则由“{<table_name>+”,”+<startKey>+”,”+<timestamp>+”.”}”)

5.split切分

  指令:>split ‘ns1:student’,’row-sm’  //将student表强制在row-sm位置切分

6.merge合并

  指令:>merge_region ‘857d52f5591906576a85809db8522cbf’,’441d5e059755eae0f0b4582e915f6408′

//后两个指的是regionname

7.move移动指令

  >move ‘441d5e059755eae0f0b4582e915f6408’  //  随机指定regionserver

  >move ‘441d5e059755eae0f0b4582e915f6408’,’slave1,16020,1533138423796’  //指定move到slave1,16020,1533138423796这个regionserver

8.预分区

  >create ‘ns1:t1’, ‘f1′, SPLITS => [’10’, ’20’, ’30’, ’40’]

    说明:在ns1命名空间下,创建t1表,列簇为f1;预分区为5个:[”,10);[10,20);[20,30);[30,40);[40,”]

 

    原文作者:hbase
    原文地址: https://www.cnblogs.com/lyr999736/p/9417694.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞