aliyun-Hbase操作记录

在日常测试中,遇到一个问题:在购买aliyun-Hbase之后,没有在页面找到对应的操作页面。这个时候,我们要怎么办?
第一步下载hbaseue-shell.tar.gz
第二步修改config/hbase-site.xml文件中hbase.zookeeper.quorum,username和password。

<property>
        <name>hbase.zookeeper.quorum</name>
        <value>xxxx</value>
    </property>
    <property>
        <name>hbase.client.username</name>
        <value>xxx</value>
    </property>
    <property>
        <name>hbase.client.password</name>
        <value>xxx</value>
    </property>

第三步,进入/bin目录下,输入启动命令:./hbase shell
image.png

Hbase的相关操作命令如下:
1、查询所有列表:list
2、查询表是否存在:exists '{table}'
3、查看表结构: describe '{table}'
4、查询表中所有内容: scan '{table}',{LIMIT=>5}
5、查询表中对应row的内容: get '{table}','{row}'
6、表中插入数据:put {table},{rowkey},{family:column},{value},{timestamp}
7、删除表中数据(列):delete {table},{rowkey},{family:column}
8、删除表中数据(行):deleteall {table},{rowkey}

Java代码链接:

public static Configuration conf = HBaseConfiguration.create();
private static HBaseAdmin admin = null;

public static HBaseAdmin createConnect() {
   conf.set("hbase.zookeeper.quorum", "IP");//此处应填你的IP地址,如果在windows下运行必须要填写
   conf.set("hbase.zookeeper.property.clientPort", "2181");
   try {
       admin = new HBaseAdmin(conf);
   } catch (IOException e) {
       e.printStackTrace();
   }
   return admin;
}

创建hbase的Table。

public void createTable(HBaseAdmin admin, String tableName, String[] columns) throws IOException {
   HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(Bytes.toBytes(tableName)));
   for (String column : columns) {
       descriptor.addFamily(new HColumnDescriptor(column));
   }
   admin.createTable(descriptor);
}

往Table里面插入数据

public void insertData(Configuration conf, String tableName, String rowKey, String colFamily, String column, String value) throws IOException {
   HTable table = new HTable(conf, tableName);
   Put put = new Put(Bytes.toBytes(rowKey));
   put.add(Bytes.toBytes(colFamily), Bytes.toBytes(column), Bytes.toBytes(value));
   table.put(put);
}

//在另一个类里面调用上面的方法。里面的HbaseConnector.conf是HBaseConfiguration.create();
@RequestMapping("/insert")
public String insert(String tableName, String colFamily, String column, String value) throws IOException {
   hBaseUtils.insertData(HbaseConnector.conf, tableName, "rowkey", colFamily, column, value);
   return "OK";
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 一、HBase简介 1.1 HBase是什么 HBase是一个分布式的、面向列的开源数据库,Hadoop 数据库。...
    这一刻_776b阅读 4,527评论 0 0
  • 简介 HBase是高可靠性,高性能,面向列,可伸缩的分布式存储系统,利用HBase技术可在廉价PC Serve...
    九世的猫阅读 6,771评论 1 6
  • 上一篇:101-BigData-29Azkaban 一、HBaes介绍 1.1、HBase简介HBase是一个分布...
    AncientMing阅读 3,923评论 0 1
  • 在对HBase进行操作之前,首先学习一下HBase的基础架构和运行原理。这里讲解了 HBase 在大数据生态圈中的...
    卡卡xx阅读 12,072评论 1 2
  • ​Hbase存储相关介绍 Region Server: 不同Region数据互斥(Table+StartKey+T...
    佛系小懒阅读 2,656评论 0 2

友情链接更多精彩内容