Hbase(二) HBase快速入门
HBase Shell操作
- 进入 hbase shell 终端
进入hbase安装根目录下;输入hbase]$ bin/hbase shell
[admin@hadoop102 hbase]$ bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/module/hbase/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/module/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.0.5, r76458dd074df17520ad451ded198cd832138e929, Mon Mar 18 00:41:49 UTC 2019
Took 0.0136 seconds
hbase(main):001:0>
- help 查看帮助文档
hbase(main):001:0> help
HBase Shell, version 2.0.5, r76458dd074df17520ad451ded198cd832138e929, Mon Mar 18 00:41:49 UTC 2019
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_block_cache, clear_compaction_queues, 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_exclude_namespaces, append_peer_exclude_tableCFs, append_peer_namespaces, 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_exclude_namespaces, remove_peer_exclude_tableCFs, remove_peer_namespaces, remove_peer_tableCFs, set_peer_bandwidth, set_peer_exclude_namespaces, set_peer_exclude_tableCFs, set_peer_namespaces, set_peer_replicate_all, 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_quota_snapshots, list_quota_table_sizes, list_quotas, list_snapshot_sizes, set_quota
Group name: security
Commands: grant, list_security_capabilities, revoke, user_permission
Group name: procedures
Commands: list_locks, 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_namespaces_rsgroup, move_servers_namespaces_rsgroup, 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
- 查看某个命令帮助文档
如:get 命令, 需要添加 双引号
hbase(main):002:0> help "get"
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions. Examples:
hbase> get 'ns1:t1', 'r1'
hbase> get 't1', 'r1'
hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]}
hbase> get 't1', 'r1', {COLUMN => 'c1'}
hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> get 't1', 'r1', 'c1'
hbase> get 't1', 'r1', 'c1', 'c2'
hbase> get 't1', 'r1', ['c1', 'c2']
hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}
hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
Besides the default 'toStringBinary' format, 'get' also supports custom formatting by
column. A user can define a FORMATTER by adding it to the column name in the get
specification. The FORMATTER can be stipulated:
1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt',
'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] }
Note that you can specify a FORMATTER by column only (cf:qualifier). You can set a
formatter for all columns (including, all key parts) using the "FORMATTER"
and "FORMATTER_CLASS" options. The default "FORMATTER_CLASS" is
"org.apache.hadoop.hbase.util.Bytes".
hbase> get 't1', 'r1', {FORMATTER => 'toString'}
hbase> get 't1', 'r1', {FORMATTER_CLASS => 'org.apache.hadoop.hbase.util.Bytes', FORMATTER => 'toString'}
The same commands also can be run on a reference to a table (obtained via get_table or
create_table). Suppose you had a reference t to table 't1', the corresponding commands
would be:
hbase> t.get 'r1'
hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
hbase> t.get 'r1', {COLUMN => 'c1'}
hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
- Group name: general:基本信息
- processlist:
hbase(main):027:0> help 'processlist'
显示regionserver任务列表。
hbase> processlist
hbase> processlist 'all'
hbase> processlist 'general'
hbase> processlist 'handler'
hbase> processlist 'rpc'
hbase> processlist 'operation'
hbase> processlist 'all','host187.example.com'
hbase> processlist 'all','host187.example.com,16020'
hbase> processlist 'all','host187.example.com,16020,1289493121758'
- status
hbase(main):028:0> help 'status'
显示集群状态。可以 'summary', 'simple', 'detailed', or 'replication'. The
default is 'summary'. Examples:
hbase> status
hbase> status 'simple'
hbase> status 'summary'
hbase> status 'detailed'
hbase> status 'replication'
hbase> status 'replication', 'source'
hbase> status 'replication', 'sink'
案例:
hbase(main):004:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 43.0000 average load
Took 0.0112 seconds
- table_help
hbase(main):029:0> help 'table_help'
Help for table-reference commands.
你可以通过'create'创建一个表,然后通过'put', 'get'等命令操作表。
请参阅标准帮助信息以了解如何使用这些命令。
但是,从0.96开始,您还可以获得对表的引用,您可以在该表上调用命令。
例如,你可以通过:
hbase> t = create 't', 'cf'
或者,如果你已经创建了这个表,你可以获得它的引用:
hbase> t = get_table 't'
You can do things like call 'put' on the table:
hbase> t.put 'r', 'cf:q', 'v'
它将一行'r'与列族'cf',限定符'q'和值'v'放入表t。
要读取数据,可以扫描表:
hbase> t.scan
它将读取表't'中的所有行。
基本上,任何带有表名的命令都可以通过表引用来执行。
其他命令包括:get、delete、deleteall、
Get_all_columns, get_counter, count, incr。这些函数,连同
标准的JRuby对象方法也可以通过tab补全获得。
要了解如何使用这些命令的更多信息,你也可以输入:
hbase> t.help 'scan'
它将输出关于如何使用该命令的更多信息。
您还可以直接在表上执行一般管理操作;比如启用,禁用,
刷新和删除只需输入:
hbase> t.enable
hbase> t.flush
hbase> t.disable
hbase> t.drop
请注意,删除表之后,对它的引用将变得无用,并将进一步使用
未定义(不推荐)。
- version
hbase(main):030:0> help 'version'
输出该hbase版本
案例:
hbase(main):007:0> version
2.0.5, r76458dd074df17520ad451ded198cd832138e929, Mon Mar 18 00:41:49 UTC 2019
Took 0.0002 seconds
- whoami
hbase(main):001:0> help 'whoami'
显示当前的hbase用户。
语法:whoami
For example:
hbase> whoami
案例
hbase(main):006:0> whoami
admin (auth:SIMPLE)
groups: admin , wheel
Took 0.0094 seconds
- Group name: ddl:
- alter
hbase(main):019:0> help 'alter'
改变一个表。可以在不禁用表的情况下修改表。
更改已启用的表会导致问题
在过去,所以使用前要谨慎,并在生产中使用前进行测试。
您可以使用alter命令添加,
修改或删除列族或更改表配置选项。
列族的工作方式与'create'命令类似。列的家庭
规范可以是名称字符串,也可以是具有name属性的字典。
字典在“help”命令的输出中进行描述,不带参数。
例如,在表't1'中更改或添加'f1'列族
current value to keep a maximum of 5 cell VERSIONS, do
hbase> alter 't1', NAME => 'f1', VERSIONS => 5
You can operate on several column families:
hbase> alter 't1', 'f1', {NAME => 'f2', IN_MEMORY => true}, {NAME => 'f3', VERSIONS => 5}
To delete the 'f1' column family in table 'ns1:t1', use one of:
hbase> alter 'ns1:t1', NAME => 'f1', METHOD => 'delete'
hbase> alter 'ns1:t1', 'delete' => 'f1'
You can also change table-scope attributes like MAX_FILESIZE, READONLY,
MEMSTORE_FLUSHSIZE, DURABILITY, etc. These can be put at the end;
for example, to change the max size of a region to 128MB, do:
hbase> alter 't1', MAX_FILESIZE => '134217728'
You can add a table coprocessor by setting a table coprocessor attribute:
hbase> alter 't1',
'coprocessor'=>'hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2'
Since you can have multiple coprocessors configured for a table, a
sequence number will be automatically appended to the attribute name
to uniquely identify it.
The coprocessor attribute must match the pattern below in order for
the framework to understand how to load the coprocessor classes:
[coprocessor jar file location] | class name | [priority] | [arguments]
You can also set configuration settings specific to this table or column family:
hbase> alter 't1', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}
hbase> alter 't1', {NAME => 'f2', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
You can also unset configuration settings specific to this table:
hbase> alter 't1', METHOD => 'table_conf_unset', NAME => 'hbase.hregion.majorcompaction'
You can also remove a table-scope attribute:
hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'MAX_FILESIZE'
hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1'
You can also set REGION_REPLICATION:
hbase> alter 't1', {REGION_REPLICATION => 2}
There could be more than one alteration in one command:
hbase> alter 't1', { NAME => 'f1', VERSIONS => 3 },
{ MAX_FILESIZE => '134217728' }, { METHOD => 'delete', NAME => 'f2' },
OWNER => 'johndoe', METADATA => { 'mykey' => 'myvalue' }
- alter_async
修改列族模式,不等待所有区域接收
模式的变化。传递表名和指定新列的字典
家庭模式。字典在主要帮助命令输出中进行了描述。
字典必须包括要更改的列族名称。例如,
从默认值中更改或添加表't1'中的'f1'列族
要保留最多5个单元格版本,请执行:
hbase> alter_async 't1', NAME => 'f1', VERSIONS => 5
To delete the 'f1' column family in table 'ns1:t1', do:
hbase> alter_async 'ns1:t1', NAME => 'f1', METHOD => 'delete'
or a shorter version:
hbase> alter_async 'ns1:t1', 'delete' => 'f1'
您还可以更改表范围属性,如MAX_FILESIZE,
MEMSTORE_FLUSHSIZE,只读的。
For example, to change the max size of a family to 128MB, do:
hbase> alter 't1', METHOD => 'table_att', MAX_FILESIZE => '134217728'
在一个命令中可以有多个更改:
hbase> alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
使用alter_status 检查是否已经更新了所有区域 <table_name>
- alter_status
hbase(main):021:0> help 'alter_status'
获取alter命令的状态。区域个数
已接收更新的模式的
通过表名。
hbase> alter_status 't1'
hbase> alter_status 'ns1:t1'
- create
hbase(main):018:0> help 'create'
创建一个表。传递一个表名和一组列族
规范(至少一个),以及可选的表配置。
列规范可以是简单的字符串(名称),也可以是字典
(字典在下面的主要帮助输出中描述)
包括名称属性。
Examples:
Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
Create a table with namespace=default and table qualifier=t1
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 1000000, MOB_COMPACT_PARTITION_POLICY => 'weekly'}
表配置选项可以放在末尾。
Examples:
hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
你也可以保留一个对已创建表的引用:
hbase> t1 = create 't1', 'f1'
它给了你一个名为't1'的表的引用,然后你可以
调用方法。
案例:
hbase(main):017:0> create 'student','info','score'
Created table student
Took 0.7443 seconds
=> Hbase::Table - student
创建一张学生表,指定两个列簇‘info’及‘score’
‘info’:用于存放学生基本信息
‘score’:用于存放学习成绩
更多方式创建方式:
- describe:描述
hbase(main):019:0> help 'describe'
Describe the named table. For example:
hbase> describe 't1'
hbase> describe 'ns1:t1'
Alternatively, you can use the abbreviated 'desc' for the same thing.
hbase> desc 't1'
hbase> desc 'ns1:t1'
案例:
hbase(main):020:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOO
MFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN =
> 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
{NAME => 'score', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLO
OMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN
=> 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
2 row(s)
Took 0.0366 seconds
或者:使用命名空间
hbase(main):022:0> describe 'default:student'
Table default:student is ENABLED
default:student
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOO
MFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN =
> 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
{NAME => 'score', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE',
CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLO
OMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN
=> 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
2 row(s)
Took 0.0270 seconds
- disable:禁用表
hbase(main):023:0> help 'disable'
禁用表名:
hbase> disable 't1' # 使用默认的命名空间
hbase> disable 'ns1:t1' # 自定义命名空间
案例:
hbase(main):015:0> disable 'student'
Took 0.5354 seconds
- disable_all:禁用所有
hbase(main):024:0> help 'disable_all'
禁用所有匹配给定正则表达式的表:
hbase> disable_all 't.*'
hbase> disable_all 'ns:t.*'
hbase> disable_all 'ns:.*'
- drop:删除表
删除已命名表。Table必须首先禁用:
hbase> drop 't1'
hbase> drop 'ns1:t1'
案例:
hbase(main):015:0> disable 'student'
Took 0.5354 seconds
hbase(main):016:0> drop 'student'
Took 0.2433 seconds
- drop_all:
hbase(main):026:0> help 'drop_all'
删除所有匹配给定正则表达式的表,需要先禁用。
hbase> drop_all 't.*'
hbase> drop_all 'ns:t.*'
hbase> drop_all 'ns:.*'
- enable
hbase(main):002:0> help 'enable'
重新启用被禁用的表
hbase> enable 't1'
hbase> enable 'ns1:t1'
- enable_all,
hbase(main):003:0> help 'enable_all'
启用所有被禁用的表,支持正则表达式
hbase> enable_all 't.*'
hbase> enable_all 'ns:t.*'
hbase> enable_all 'ns:.*'
- exists
检查表是否存在
hbase> exists 't1'
hbase> exists 'ns1:t1'
案例
hbase(main):006:0> exists 'student'
Table student does exist
Took 0.2531 seconds
=> true
- get_table
hbase(main):007:0> help 'get_table'
获取给定的表名,并将其作为实际对象返回
被用户操纵。见下表。有关更多信息的帮助
关于如何使用表格。
Eg.
hbase> t1 = get_table 't1'
hbase> t1 = get_table 'ns1:t1'
返回名为't1'的表作为表对象。你可以这样做
hbase> t1.help
然后它将打印该表的帮助。
案例
hbase(main):009:0> t1=get_table 'student'
Took 0.0002 seconds
=> Hbase::Table - student
hbase(main):010:0> t1.help
- is_disabled,
hbase(main):011:0> help 'is_disabled'
校验是否被禁用
hbase> is_disabled 't1'
hbase> is_disabled 'ns1:t1'
- is_enabled,
校验是否启用
hbase> is_enabled 't1'
hbase> is_enabled 'ns1:t1'
- list,
hbase(main):013:0> help 'list'
列出hbase中所有的用户表。可选的正则表达式参数可以
用于过滤输出。例子:
hbase> list
hbase> list 'abc.*'
hbase> list 'ns:abc.*'
hbase> list 'ns:.*'
案例
hbase(main):014:0> list
TABLE
PERSON
SYSTEM.CATALOG
SYSTEM.FUNCTION
SYSTEM.LOG
SYSTEM.MUTEX
SYSTEM.SEQUENCE
SYSTEM.STATS
bigData2:t1
student
user
10 row(s)
Took 0.0282 seconds
=> ["PERSON", "SYSTEM.CATALOG", "SYSTEM.FUNCTION", "SYSTEM.LOG", "SYSTEM.MUTEX", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "bigData2:t1", "student", "user"]
- list_regions,
hbase(main):015:0> help 'list_regions'
以数组的形式列出特定表的所有区域,并以服务器名(可选)作为前缀过滤它们
最大局部性(可选)。默认情况下,它将返回具有任何局部性的表的所有区域。
该命令显示服务器名称、区域名称、开始键、结束键、区域大小(以MB为单位)、请求数
和位置。信息可以通过一个数组作为第三个参数投影出来。默认情况下所有这些信息
会显示出来。可能的数组值为SERVER_NAME、REGION_NAME、START_KEY、END_KEY、SIZE、REQ和LOCALITY。值
不区分大小写。如果您不想按服务器名进行过滤,请传递一个空散列/字符串,如下所示。
Examples:
hbase> list_regions 'table_name'
hbase> list_regions 'table_name', 'server_name'
hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}
hbase> list_regions 'table_name', {SERVER_NAME => 'server_name', LOCALITY_THRESHOLD => 0.8}, ['SERVER_NAME']
hbase> list_regions 'table_name', {}, ['SERVER_NAME', 'start_key']
hbase> list_regions 'table_name', '', ['SERVER_NAME', 'start_key']
案例:虽然懵懵懂懂,但是看到START_KEY ,END_KEY 基本上明白有啥用了。
hbase(main):016:0> list_regions 'student'
SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
----------------------------- | -------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
hadoop102,16020,1623911670801 | student,,1623915125205.9e5c8dc24f8937ef1e56e1d4eb1122a0. | | | 0 | 0 | 0.0 |
1 rows
Took 0.1017 seconds
- locate_region,
hbase(main):017:0> help 'locate_region'
找到给定表名和行键的区域
hbase> locate_region 'tableName', 'key0'
- show_filters
hbase(main):017:0> help 'locate_region'
找到给定表名和行键的区域
hbase> locate_region 'tableName', 'key0'
hbase(main):018:0> help 'show_filters'
Show all the filters in hbase. Example:
hbase> show_filters
ColumnPrefixFilter
TimestampsFilter
PageFilter
.....
KeyOnlyFilter
- Group name: namespace:命名空间
- alter_namespace
hbase(main):022:0> help 'alter_namespace'
改变名称空间的属性。
To add/modify a property:
hbase> alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
To delete a property:
hbase> alter_namespace 'ns1', {METHOD => 'unset', NAME=>'PROPERTY_NAME'}
- create_namespace
hbase(main):023:0> help 'create_namespace'
创建名称空间;通过名称空间的名字,
还可以选择命名空间配置字典。
Examples:
hbase> create_namespace 'ns1'
hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
- describe_namespace
hbase(main):024:0> help 'describe_namespace'
描述命名的命名空间。例如:
hbase> describe_namespace 'ns1'
- drop_namespace
hbase(main):025:0> help 'drop_namespace'
删除命名的命名空间。命名空间必须为空。
- list_namespace
hbase(main):026:0> help 'list_namespace'
列出hbase中所有的命名空间。可选的正则表达式参数可以
用于过滤输出。例子:
hbase> list_namespace
hbase> list_namespace 'abc.*'
- list_namespace_tables
列出作为名称空间成员的所有表。
Examples:
hbase> list_namespace_tables 'ns1'
-
Group name: dml
t1 :表名
r1 :列名
c1 :列簇
value : 插入的值
- append
hbase(main):028:0> help 'append'
在指定的表/行/列坐标上附加单元格“值”。
hbase> append 't1', 'r1', 'c1', 'value', ATTRIBUTES=>{'mykey'=>'myvalue'}
hbase> append 't1', 'r1', 'c1', 'value', {VISIBILITY=>'PRIVATE|SECRET'}
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
hbase> t.append 'r1', 'c1', 'value', ATTRIBUTES=>{'mykey'=>'myvalue'}
hbase> t.append 'r1', 'c1', 'value', {VISIBILITY=>'PRIVATE|SECRET'}
案例:
hbase(main):043:0> append 'student', 'sex', 'info', 'M'
CURRENT VALUE = M
Took 0.0134 seconds
- count
hbase(main):045:0> help 'count'
计算表中的行数。返回值是行数。
执行此操作可能会花费较长时间(请执行“$HADOOP_HOME/bin/hadoop jar . bat”命令)
Hbase.jar rowcount'来运行一个计数mapreduce作业)。显示当前计数
默认每1000行。可选择指定计数间隔。扫描
缓存默认在计数扫描时启用。默认的缓存大小是10行。
如果您的行很小,您可能想要增加它
parameter. Examples:
hbase> count 'ns1:t1'
hbase> count 't1'
hbase> count 't1', INTERVAL => 100000
hbase> count 't1', CACHE => 1000
hbase> count 't1', INTERVAL => 10, CACHE => 1000
hbase> count 't1', FILTER => "
(QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"
hbase> count 't1', COLUMNS => ['c1', 'c2'], STARTROW => 'abc', STOPROW => 'xyz'
同样的命令也可以在表引用上运行。假设你有一个参考
T到表't1',对应的命令为:
hbase> t.count
hbase> t.count INTERVAL => 100000
hbase> t.count CACHE => 1000
hbase> t.count INTERVAL => 10, CACHE => 1000
hbase> t.count FILTER => "
(QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"
hbase> t.count COLUMNS => ['c1', 'c2'], STARTROW => 'abc', STOPROW => 'xyz'
案例:
hbase(main):046:0> count 'student'
3 row(s)
Took 0.0249 seconds
=> 3
hbase(main):047:0> t1=get_table 'student'
Took 0.0002 seconds
=> Hbase::Table - student
hbase(main):048:0> t1.count
3 row(s)
Took 0.0032 seconds => 3
- delete
hbase(main):050:0> help 'delete'
在指定的表/行/列中放置一个删除单元格值
时间戳的坐标。删除必须匹配已删除的单元格
确切的坐标。扫描时,删除单元格会抑制旧单元格
版本。delete a cell from 't1' at row 'r1' under column 'c1'
以时间'ts1'标记,做:
hbase> delete 'ns1:t1', 'r1', 'c1', ts1
hbase> delete 't1', 'r1', 'c1', ts1
hbase> delete 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
同样的命令也可以在表引用上运行。假设你有一个参考
T到表't1',对应的命令为:
hbase> t.delete 'r1', 'c1', ts1
hbase> t.delete 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
案例:
hbase(main):052:0> delete 'student','score','score' #之前的插入的错误数据 score。
Took 0.0090 seconds
hbase(main):053:0> t1.count
2 row(s)
Took 0.0058 seconds => 2
- deleteall
hbase(main):054:0> help 'deleteall'
删除给定行的所有单元格;传递表名、行和可选参数
列和时间戳。Deleteall还支持使用
rowkey 前缀,案例:
hbase> deleteall 'ns1:t1', 'r1'
hbase> deleteall 't1', 'r1'
hbase> deleteall 't1', 'r1', 'c1'
hbase> deleteall 't1', 'r1', 'c1', ts1
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
ROWPREFIXFILTER 可以用来删除行范围吗
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1' //删除行范围中的某些列族
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
缓存可以用来指定一次批量发送给服务器的删除数量,默认为100
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix', CACHE => 100}
同样的命令也可以在表引用上运行。假设你有一个参考
T到表't1',对应的命令为:
hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> t.deleteall {ROWPREFIXFILTER => 'prefix', CACHE => 100}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
- get
hbase(main):055:0> help 'get'
获取行或单元格内容;传递表名、行和可选参数
包含列、时间戳、时间范围和版本的字典。例子:
hbase> get 'ns1:t1', 'r1'
hbase> get 't1', 'r1'
hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]}
hbase> get 't1', 'r1', {COLUMN => 'c1'}
hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> get 't1', 'r1', 'c1'
hbase> get 't1', 'r1', 'c1', 'c2'
hbase> get 't1', 'r1', ['c1', 'c2']
hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}
hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
Besides the default 'toStringBinary' format, 'get' also supports custom formatting by
column. A user can define a FORMATTER by adding it to the column name in the get
specification. The FORMATTER can be stipulated:
1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString)
2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'.
Example formatting cf:qualifier1 and cf:qualifier2 both as Integers:
hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt',
'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] }
Note that you can specify a FORMATTER by column only (cf:qualifier). You can set a
formatter for all columns (including, all key parts) using the "FORMATTER"
and "FORMATTER_CLASS" options. The default "FORMATTER_CLASS" is
"org.apache.hadoop.hbase.util.Bytes".
hbase> get 't1', 'r1', {FORMATTER => 'toString'}
hbase> get 't1', 'r1', {FORMATTER_CLASS => 'org.apache.hadoop.hbase.util.Bytes', FORMATTER => 'toString'}
The same commands also can be run on a reference to a table (obtained via get_table or
create_table). Suppose you had a reference t to table 't1', the corresponding commands
would be:
hbase> t.get 'r1'
hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
hbase> t.get 'r1', {COLUMN => 'c1'}
hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
案例:
hbase(main):056:0> get 'student','name'
COLUMN CELL
info: timestamp=1623919980380, val
ue=zhangsan
1 row(s)
Took 0.0123 seconds
hbase(main):057:0> get 'student','name','info'
COLUMN CELL
info: timestamp=1623919980380, val
ue=zhangsan
1 row(s)
Took 0.0046 seconds
- get_counter
hbase(main):062:0> help 'get_counter'
返回指定表/行/列坐标处的计数器单元格值。
计数器单元应该用HBase上的原子增量函数来管理
并且数据应该是二进制编码的(作为长值)。例子:
hbase> get_counter 'ns1:t1', 'r1', 'c1'
hbase> get_counter 't1', 'r1', 'c1'
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
hbase> t.get_counter 'r1', 'c1'
案例:
hbase(main):069:0> incr 'student','name','info:no',1
COUNTER VALUE = 1
Took 0.0058 seconds
hbase(main):070:0> get_counter 'student','name','info:no'
COUNTER VALUE = 1
- get_splits
hbase(main):074:0> help 'get_splits'
Get the splits of the named table:
hbase> get_splits 't1'
hbase> get_splits 'ns1:t1'
同样的命令也可以在表引用上运行。假设你有一个参考
T到表't1',对应的命令为:
hbase> t.get_splits
案例:
hbase(main):076:0> get_splits 'student'
Total number of splits = 1
Took 0.0084 seconds
=> []
- incr
hbase(main):073:0> help 'incr'
在指定的表/行/列坐标处增加单元格的“值”。
增加表'ns1:t1'或列下行'r1'中的't1'中的单元格值
'c1' × 1(可以省略)或10 do:
hbase> incr 'ns1:t1', 'r1', 'c1'
hbase> incr 't1', 'r1', 'c1'
hbase> incr 't1', 'r1', 'c1', 1
hbase> incr 't1', 'r1', 'c1', 10
hbase> incr 't1', 'r1', 'c1', 10, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> incr 't1', 'r1', 'c1', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> incr 't1', 'r1', 'c1', 10, {VISIBILITY=>'PRIVATE|SECRET'}
同样的命令也可以在表引用上运行。假设你有一个参考
T到表't1',对应的命令为:
hbase> t.incr 'r1', 'c1'
hbase> t.incr 'r1', 'c1', 1
hbase> t.incr 'r1', 'c1', 10, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> t.incr 'r1', 'c1', 10, {VISIBILITY=>'PRIVATE|SECRET'}
案例:
hbase(main):069:0> incr 'student','name','info:no',1
COUNTER VALUE = 1
Took 0.0058 seconds
- put
hbase(main):034:0> help 'put'
在指定的表/行/列中放置一个单元格“值”
时间戳的坐标。将单元格值放入表'ns1:t1'或't1'中
在列'c1'下的'r1'行,标记时间'ts1', do:
hbase> put 'ns1:t1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value', ts1
hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase(main):035:0>
案例:
hbase(main):058:0> put 'student','name','info','lisi'
Took 0.0044 seconds
hbase(main):059:0> get 'student','name','info'
COLUMN CELL
info: timestamp=1623920965276, value=lisi
1 row(s)
Took 0.0067 seconds
hbase(main):060:0> put 'student', 'name', 'info', 'wangwu', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
Took 0.0038 seconds
hbase(main):061:0> get 'student','name','info'
COLUMN CELL
info: timestamp=1623921051140, value=wangwu
1 row(s)
Took 0.0064 seconds
-
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_block_cache, clear_compaction_queues, 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_dumpGroup name: replication
Commands: add_peer, append_peer_exclude_namespaces, append_peer_exclude_tableCFs, append_peer_namespaces, 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_exclude_namespaces, remove_peer_exclude_tableCFs, remove_peer_namespaces, remove_peer_tableCFs, set_peer_bandwidth, set_peer_exclude_namespaces, set_peer_exclude_tableCFs, set_peer_namespaces, set_peer_replicate_all, set_peer_tableCFs, show_peer_tableCFs, update_peer_configGroup name: snapshots
Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshotGroup name: configuration
Commands: update_all_config, update_configGroup name: quotas
Commands: list_quota_snapshots, list_quota_table_sizes, list_quotas, list_snapshot_sizes, set_quotaGroup name: security
Commands: grant, list_security_capabilities, revoke, user_permissionGroup name: procedures
Commands: list_locks, list_proceduresGroup name: visibility labels
Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibilityGroup name: rsgroup
Commands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_namespaces_rsgroup, move_servers_namespaces_rsgroup, move_servers_rsgroup, move_servers_tables_rsgroup, move_tables_rsgroup, remove_rsgroup, remove_servers_rsgroup