【四】HBase Shell命令

shell命令

创建表 create

create 'tablename','column family1','column family2' 

create 'wc','cf'

添加记录 put

put 'tablename','row key','column family:column name','value'

put 'wc','hello','cf:hello','5'

put 'wc','hello','cf:word','hello'

put 'wc','hello','cf:value','5'

查看某行 get

get 'tablename','row key'

get 'wc','hello'

查看某个列族

get 'tablename','row key',{COLUMN => 'column family'}

get 'wc','hello',{COLUMN => 'cf'}

查看某个单元格

get 'tablename','row key',{COLUMN => 'column family:column name'}

get 'wc','hello',{COLUMN => 'cf:hello'}

查看表中的记录总数 count

count 'tablename'

count 'wc'

删除单元格 delete

delete 'tablename','row key','column family:column name'

delete 'wc','hello','cf:hello'

删除整行 delete。

deleteall 'tablename','row key'

deleteall 'wc','hello'

删除一张表,先要屏蔽该表再删除 drop

disable 'tablename'

drop 'tablename'

查看表中所有记录 scan

scan 'tablename'

scan 'wc'

修改记录

就是重新插入一条row key相同的数据即可。没有update的用法。

查看有哪些表 list

list

alter

alter ‘tablename’,NAME=>’familyname’,attribute=>new_value 

给表添加列族 alter

添加一个名字叫sid的列族VERSIONS值为5

alter 'wc',NAME=>'sid',VERSION=>5

将表设置为只读模式 
alter ‘tablename’,READONLY 
删除表范围运算符,需首先将表disable
alter ‘tablename’,METHOD=>’table_att_unset’,NAME=>’MAX_FILESIZE’ 
删除列族,需首先将表disable
alter ‘tablename’,’delete’=>’column family’ 
删除一个列族之后,这个列族的数据也会全部被删除。

修改表的cf的TTL为180天
disable 'tablename'
alter 'tablename',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}

enable 'tablename'

incr 计数器

incr 'tablename','rowkey','column family:column' step     step是步长,可选,默认为1

给‘id’这个行健增加'column_famaly1:addr'字段,并使用counter实现递增

hbase(main):002:0> incr 'table','id','column_famaly1:addr'
COUNTER VALUE = 1
0 row(s) 


hbase(main):003:0> incr 'table','id','column_famaly1:addr'
COUNTER VALUE = 2
0 row(s) 

hbase(main):004:0> get 'table','id','column_famaly1:addr'
COLUMN                CELL                                                      
 column_famaly1:addr  timestamp=1463056705124, value=\x00\x00\x00\x00\x00\x00\x0
                      0\x02                                                     
1 row(s) 

hbase(main):005:0> incr 'table','id','column_famaly1:addr'
COUNTER VALUE = 3
0 row(s)

 获取计数器当前值

get_counter 'tablename','rowkey','column family:column'

 

组命令Group name

general

status 查看当前集群状态

查看当前用户是谁

whoami

namespace

创建命名空间

create_namespace 'ns name'

create_namespace 'sid'

查看有哪些命名空间

list_namespace

删除命名空间

drop_namespace 'ns name'

其他命令,输入help会显示。这里不做过多介绍。

hbase(main):004:0> help
HBase Shell, version 1.4.4, rfe146eb48c24d56dbcd2f669bb5ff8197e6c918b, Sun Apr 22 20:42:02 PDT 2018
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:
  Group name: general
  Commands: processlist, status, table_help, version, whoami

  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, list_regions, locate_region, show_filters

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

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

  Group name: tools
  Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, cleaner_chore_enabled, cleaner_chore_run, cleaner_chore_switch, clear_deadservers, close_region, compact, compact_rs, compaction_state, flush, is_in_maintenance_mode, list_deadservers, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, splitormerge_enabled, splitormerge_switch, trace, unassign, wal_roll, zk_dump

  Group name: replication
  Commands: add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, get_peer_config, list_peer_configs, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_bandwidth, set_peer_tableCFs, show_peer_tableCFs, update_peer_config

  Group name: snapshots
  Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshot

  Group name: configuration
  Commands: update_all_config, update_config

  Group name: quotas
  Commands: list_quotas, set_quota

  Group name: security
  Commands: grant, list_security_capabilities, revoke, user_permission

  Group name: procedures
  Commands: abort_procedure, list_procedures

  Group name: visibility labels
  Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility

  Group name: rsgroup
  Commands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_servers_rsgroup, move_servers_tables_rsgroup, move_tables_rsgroup, remove_rsgroup, remove_servers_rsgroup

SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:

  {'key1' => 'value1', 'key2' => 'value2', ...}

and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.

If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:

  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"

The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/book.html

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值