hbase--客户端操作

1、客户端

  • hbase
[root@node-01 hbase-1.2.0-cdh5.14.0]# hbase
Usage: hbase [<options>] <command> [<args>]

Commands:
Some commands take arguments. Pass no args or -h for usage.
  shell           Run the HBase shell
  hbck            Run the hbase 'fsck' tool
  snapshot        Create a new snapshot of a table
  snapshotinfo    Tool for dumping snapshot information
  wal             Write-ahead-log analyzer
  hfile           Store file analyzer
  zkcli           Run the ZooKeeper shell
  upgrade         Upgrade hbase
  master          Run an HBase HMaster node
  regionserver    Run an HBase HRegionServer node
  zookeeper       Run a Zookeeper server
  rest            Run an HBase REST server
  thrift          Run the HBase Thrift server
  thrift2         Run the HBase Thrift2 server
  clean           Run the HBase clean up script
  classpath       Dump hbase CLASSPATH
  mapredcp        Dump CLASSPATH entries required by mapreduce
  pe              Run PerformanceEvaluation
  ltt             Run LoadTestTool
  version         Print the version
  CLASSNAME       Run the class named CLASSNAME
  • hbase shell
    • 运行hbase 的客户端命令行
    • 退出:exit
    • 注意事项一
      • 不支持SQL语句
      • 不支持SQL语句
      • 不支持SQL语句
      • 命令不能用分号结尾
      • 命令不能用分号结尾
      • 命令不能用分号结尾
    • 查看命令帮助文档
      • HBase Shell; enter ‘help’ for list of supported commands.
      • help
    • 注意事项二
      • 这个命令行如果写错了,删除不能直接按backspace按键
      • 默认删除是向后删除
      • 按住ctrl+backspace删除键可以向前删除(或者设置会话选项里的映射键,打两个√)

2、DDL

NameSpace的管理

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
  • 如果不知道某个命令的用法
help 'command'
help 'create_namespace'

创建

  • 语法
    • create_namespace ‘ns1’
  • 测试
    • create_namespace ‘hanjiaxiaozhi01’
    • create_namespace ‘hanjiaxiaozhi02’
    • create_namespace ‘student’

列举

list_namespace

删除

drop_namespace 'hanjiaxiaozhi02'
  • 列举某个namespace中所有的表
    在这里插入图片描述

表的管理

Group name: ddl
  Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters
  • 官方文档中的缩写的含义
    • ns:namespace
    • t:table
    • r:rowkey
    • f:列族
    • c:列
    • v:值
    • ts:时间戳

创建

  • 必须指定在哪个namespace中创建表,如果不指定,就默认在default的namespace中创建
  • 必须指定表的名称
  • 必须至少指定创建一个列族
  • 方式一:直接给定列族的名称,不需要配置列族的属性
create 'ns1:t1', 'f1'
create 'ns1:t1', 'f1','f2'
  • 测试
create 'hanjiaxiaozhi01:hanjiaxiaozhi','cf1'
create 'heima' ,'cf1','cf2'
  • 不加ns,就代表操作default的ns
  • 方式二:需要更改列族的属性
create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
  • 测试
create 'student:stu3',{NAME=>'basic',VERSIONS=>3},'other'

列举

  • list

删除

  • 语法
drop  'nsname:tbname'
  • 测试
drop  'heima'
  • 注意
    • Hbase所有的表是有两种状态
    • ENABLED启动状态:可以正常读写的表
    • Disable禁用状态:不可以读写
  • 需要修改或者删除Hbase表,必须先禁用
    • 为了避免有人正在使用这张表,而突然修改导致不一致性的出现
    • 修改成功以后,要重新启用表,这张表才可用
  • 测试
disable 'heima'
drop 'heima'
  • 启用表
enable 'ns:tbname'
  • 禁用表
disable 'ns:tbname'
  • 描述
desc 'hanjiaxiaozhi01:hanjiaxiaozhi'

{NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 
desc 'heima'
                                                        
{NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}               
{NAME => 'cf2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
 => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}               
desc 'student:stu'
                                                                 
{NAME => 'basic', BLOOMFILTER => 'ROW', VERSIONS => '3', IN_MEMORY => 'false', KEEP_DELETED_CEL
LS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERS
IONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}             
{NAME => 'other', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CEL
LS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERS
IONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}             
2 row(s) in 0.2280 seconds

3、DML【增删改查】

Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

put:插入数据/更新数据【类似于mysql中的replace,如果不存在就插入,如果存在就更新】

  • 功能:为Hbase表的某一行插入一列
  • 语法
put 'ns1:t1', 'r1', 'c1', 'value'
put 't1', 'r1', 'c1', 'value', ts1
  • 测试
put 'student:stu','20200101_001','basic:name','laoda'
put 'student:stu','20200101_001','basic:age',18
put 'student:stu','20200101_001','basic:sex','male'
put 'student:stu','20200101_001','other:phone','110'
put 'student:stu','20200101_001','other:addr','shanghai'

put 'student:stu','20200103_002','basic:name','laoer'
put 'student:stu','20200103_002','basic:age',20
put 'student:stu','20200103_002','other:phone','119'

put 'student:stu','20200102_003','basic:name','laosan'
put 'student:stu','20200102_003','other:phone','120'
put 'student:stu','20200102_003','other:addr','beijing'
  • 更新
put 'student:stu','20200103_002','basic:name','laosi'
scan 'student:stu',{VERSIONS=>10}

get:获取数据

  • 功能:最多返回一个rowkey的所有数据
  • 查询最快的方式
  • 为什么:必须指定rowkey,rowkey是底层Hbase的索引
  • 语法
get 'ns1:t1', 'r1'
get 'ns1:t1', 'r1','c1'
  • 测试
get 'student:stu','20200103_002'
get 'student:stu','20200103_002','basic'
get 'student:stu','20200103_002','basic:name'

delete:删除数据

  • 功能:删除某列或者某个版本的数据
  • 语法
delete 'ns1:t1', 'r1', 'c1', ts1
  • 测试
delete 'student:stu','20200102_003','other:phone'

scan:扫描数据

  • 用法一:scan ‘ns:tbname’
    • 扫描全表
scan 'student:stu'
  • 用法二:scan ‘ns:tbname’ + 过滤器
    • 过滤查询
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
hbase-client-project-2.4.16.jar是一个用于连接HBase数据库的Java客户端项目。HBase是一个分布式、面向列的NoSQL数据库,它可以存储大规模数据,并提供高可靠性和高性能的数据访问。而hbase-client-project-2.4.16.jar则是用来连接HBase数据库的Java客户端库。通过这个库,开发人员可以在Java应用中方便地访问HBase数据库,进行数据的读取、写入和管理操作hbase-client-project-2.4.16.jar库提供了丰富的API,使得开发人员可以编写简洁、高效的代码来操作HBase数据库。通过这个库,可以轻松地建立与HBase集群的连接,创建、删除表格,进行数据的增删改查等操作。此外,hbase-client-project-2.4.16.jar也提供了一些高级特性,比如支持过滤器、批量操作、数据版本控制等功能,让开发人员能够更加灵活地利用HBase数据库进行数据处理。 除此之外,hbase-client-project-2.4.16.jar还支持与HBase的安全认证和权限控制,可以保障数据访问的安全性。开发人员可以使用这个库来编写安全的Java应用,确保对HBase数据库的数据进行合法、受控的访问。 总之,hbase-client-project-2.4.16.jar是一个强大、灵活的Java客户端库,为开发人员提供了便捷的方式来连接、操作HBase数据库。无论是小规模的应用还是大规模的数据处理需求,它都能够满足开发人员的要求,帮助他们更有效地利用HBase数据库。 (字数: 258)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值