Hadoop-Hbase基础操作命令

1. 创建表

create 'music_table','meta_data','action'

2. 查询表列表

list

3. 查看表的具体描述

describe 'music_table'

4. 禁用表

disable 'music_table'

5. 激活表

enable 'music_table'

6. 查看表是否被激活

is_enabled 'music_table' 

7. 删除表(删除表之前,必须要先禁用表)

drop 'music_table'

8. 查看表是否存在

exists 'music_table'

9. 插入一条数据

put 'music_table', '111', 'meta_data:name', '2002xue'
put 'music_table', '111', 'meta_data:desc', '4444'

10. 查询

get 'music_table', '111'

11. 查询全表(数据大时,慎用)

scan 'music_table'

12. 指定版本查询数据

get 'music_table', '111', {COLUMN=>'meta_data:desc',TIMESTAMP=>1526567134684}

13. 查询最新的版本

get 'music_table', '111', {COLUMN=>'meta_data:desc'}

14. 修改版本存储个数:(试了之后好像不起作用)

alter 'music_table', '111', {COLUMN=>'meta_data:desc',VERSIONS=>3}

15. 查看有多少条记录

count 'music_table'

16. 删除表中指定的列族

delete 'music_table', '111', 'meta_data:desc'

17. 删除整行

deleteall 'music_table', '111'

18. 查询全表

scan 'music_table'

19. 截断表(背后的过程是:先禁用,后清空表)

truncate 'music_table'

Hbase 基本操作类 static { //此处可以使用hbase的配置文件,也可以通过代码来实例化hbase连接 /* * Configuration HBASE_CONFIG = new Configuration(); * HBASE_CONFIG.set("hbase.zookeeper.quorum", "10.229.171.45"); * HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181"); * HBASE_CONFIG.set("hbase.zookeeper.quorum","10.233.92.85,10.233.92.86,10.233.92.88"); * HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181"); * HBASE_CONFIG.set("zookeeper.znode.parent", "/hbase-unsecure"); conf = HBaseConfiguration.create(HBASE_CONFIG); */ conf = HBaseConfiguration.create(); if("kerberos".equals(conf.get("hbase.security.authentication"))){ try { //设置hadoop.security.authentication为kerberos conf.set("hadoop.security.authentication", "kerberos"); //获取kerberos配置文件路径(krb为kerberos配置文件) String krbStr=Thread.currentThread().getContextClassLoader().getResource("krb").getFile(); //获取用户票据hezhong路径(hezhong为给合众分配的用户配置文件) String keyStr=Thread.currentThread().getContextClassLoader().getResource("jdzy").getFile(); //初始化配置文件 System.setProperty("java.security.krb5.conf", krbStr); //使用用户hezhong登录 UserGroupInformation.setConfiguration(conf); UserGroupInformation.loginUserFromKeytab("jdzy/f04345e6-70c1-448a-9bbb-4ac6b4c0109b@POLICE.COM", keyStr); } catch (IOException e) { e.printStackTrace(); } } tablePool = new HTablePool(conf, poolsize); logger.debug("create hbase connection success"); // System.out.println("create hbase connection success"); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值