连接服务器
- 服务器版自带连接客户端或者下载专用客户端hbase-2.2.3-client-bin.tar.gz安装包
- 打开客户端连接工具:/usr/local/hbase-2.2.3/bin/hbase shell
其中:出现第9行表示连接服务器端成功[root@hbase111 hbase-2.2.3]# ./bin/hbase shell
2020-02-05 09:54:53,967 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
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.2.3, r6a830d87542b766bd3dc4cfdee28655f62de3974, 2020年 01月 10日 星期五 18:27:51 CST
Took 0.0089 seconds
hbase(main):001:0>
帮助命令
查看客户端支持的命令帮助
- help “${命令}”:查看特定的命令帮助,用双引号括起来
- help:查看所有支持的命令
hbase(main):001:0> help
HBase Shell, version 2.2.3, r6a830d87542b766bd3dc4cfdee28655f62de3974, 2020年 01月 10日 星期五 18:27:51 CST
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, clone_table_schema, 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, compaction_switch, decommission_regionservers, flush, hbck_chore_run, is_in_maintenance_mode, list_deadservers, list_decommissioned_regionservers, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, recommission_regionserver, regioninfo, rit, split, splitormerge_enabled, splitormerge_switch, stop_master, stop_regionserver, 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_serial, 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: disable_exceed_throttle_quota, disable_rpc_throttle, enable_exceed_throttle_quota, enable_rpc_throttle, 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
查看特定命令的帮助:whoami命令
hbase(main):008:0> help "whoami"
Show the current hbase user.
Syntax : whoami
For example:
hbase> whoami
创建表
create命令,必须要指明表名和列簇名
- 创建表test,列簇为cf
hbase(main):009:0> create 'test','cf' Created table test Took 1.9637 seconds => Hbase::Table - test
查看表信息
list:查看表对象信息,可用于确认表是否存储 describe:查看单个表的详细信息
list命令
查看存在的表test的对象信息
hbase(main):013:0> list 'test' TABLE test 1 row(s) Took 0.0207 seconds => ["test"]
查看不存在的表test2的对象信息
hbase(main):014:0> list 'test2' TABLE 0 row(s) Took 0.0471 seconds => []
describe命令
- 查看存在的表test表详细信息
```shell
hbase(main):015:0> describe ‘test’
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => ‘cf’, VERSIONS => ‘1’, EVICT_BLOCKS_ON_CLOSE => ‘false’, NEW_VERSION_BEHAVIOR => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, CACHE_DATA_ON_WRITE => ‘fal se’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘FOREVER’, MIN_VERSIONS => ‘0’, REPLICATION_SCOPE => ‘0’, BLOOMFILTER => ‘ROW’, CACHE_INDEX_ON_WRITE => ‘false’, I N_MEMORY => ‘false’, CACHE_BLOOMS_ON_WRITE => ‘false’, PREFETCH_BLOCKS_ON_OPEN => ‘false’, COMPRESSION => ‘NONE’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’}
1 row(s)
QUOTAS
0 row(s)
Took 0.6644 seconds
2. 查看不存在的表test2的表详细信息
```shell
hbase(main):016:0> describe 'test2'
ERROR: Table test2 does not exist.
For usage try 'help "describe"'
Took 0.0140 seconds
数据操作
对表进行增删改查操作
新增数据
put命令:向表中增加数据,指明表名,行、列簇和对应的值
hbase(main):017:0> put 'test' ,'row1','cf:a','value1'
Took 0.1950 seconds
hbase(main):018:0> put 'test' ,'row1','cf:b','value2'
Took 0.0128 seconds
hbase(main):019:0> put 'test' ,'row1','cf:c','value3'
Took 0.0086 seconds
查看数据
scan命令:参数为表名 get命令:查看特定表单行数据
查看全表数据
hbase(main):020:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1580872272180, value=value1 row1 column=cf:b, timestamp=1580872279715, value=value2 row1 column=cf:c, timestamp=1580872284058, value=value3 1 row(s) Took 0.0672 seconds
查看单行数据
hbase(main):027:0> get 'test','row1' COLUMN CELL cf:a timestamp=1580872272180, value=value1 cf:b timestamp=1580872279715, value=value2 cf:c timestamp=1580872284058, value=value3 1 row(s) Took 0.0333 seconds
禁用/启用表
disable命令:禁用表,后面跟表名
- 查看表test状态
```shell
hbase(main):035:0> describe ‘test’
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => ‘cf’, VERSIONS => ‘1’, EVICT_BLOCKS_ON_CLOSE => ‘false’, NEW_VERSION_BEHAVIOR => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, CACHE_DATA_ON_WRITE => ‘fal se’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘FOREVER’, MIN_VERSIONS => ‘0’, REPLICATION_SCOPE => ‘0’, BLOOMFILTER => ‘ROW’, CACHE_INDEX_ON_WRITE => ‘false’, I N_MEMORY => ‘false’, CACHE_BLOOMS_ON_WRITE => ‘false’, PREFETCH_BLOCKS_ON_OPEN => ‘false’, COMPRESSION => ‘NONE’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’}
1 row(s)
QUOTAS
0 row(s)
Took 0.1776 seconds
其中:第2行显示当前表处于启用状态
2. 禁用test表
```shell
hbase(main):036:0> disable 'test'
Took 0.7397 seconds
- 再次查看表状态
```shell
hbase(main):037:0> describe ‘test’
Table test is DISABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => ‘cf’, VERSIONS => ‘1’, EVICT_BLOCKS_ON_CLOSE => ‘false’, NEW_VERSION_BEHAVIOR => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, CACHE_DATA_ON_WRITE => ‘fal se’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘FOREVER’, MIN_VERSIONS => ‘0’, REPLICATION_SCOPE => ‘0’, BLOOMFILTER => ‘ROW’, CACHE_INDEX_ON_WRITE => ‘false’, I N_MEMORY => ‘false’, CACHE_BLOOMS_ON_WRITE => ‘false’, PREFETCH_BLOCKS_ON_OPEN => ‘false’, COMPRESSION => ‘NONE’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’}
1 row(s)
QUOTAS
0 row(s)
Took 0.1784 seconds
其中:第2行显示当前表处于禁用状态
4. 启用test表
```shell
hbase(main):039:0> enable 'test'
Took 0.7457 seconds
- 再次查看test表状态
```shell
hbase(main):040:0> describe ‘test’
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => ‘cf’, VERSIONS => ‘1’, EVICT_BLOCKS_ON_CLOSE => ‘false’, NEW_VERSION_BEHAVIOR => ‘false’, KEEP_DELETED_CELLS => ‘FALSE’, CACHE_DATA_ON_WRITE => ‘fal se’, DATA_BLOCK_ENCODING => ‘NONE’, TTL => ‘FOREVER’, MIN_VERSIONS => ‘0’, REPLICATION_SCOPE => ‘0’, BLOOMFILTER => ‘ROW’, CACHE_INDEX_ON_WRITE => ‘false’, I N_MEMORY => ‘false’, CACHE_BLOOMS_ON_WRITE => ‘false’, PREFETCH_BLOCKS_ON_OPEN => ‘false’, COMPRESSION => ‘NONE’, BLOCKCACHE => ‘true’, BLOCKSIZE => ‘65536’}
1 row(s)
QUOTAS
0 row(s)
Took 0.3158 seconds
其中:第2行显示当前表处于启用状态
<a name="J42v3"></a>
# 删除表
> drop命令:删除表,后跟表名作为参数,只能删除禁用状态的表
1. 删除未禁用的表
```shell
hbase(main):041:0> drop 'test'
ERROR: Table test is enabled. Disable it first.
For usage try 'help "drop"'
Took 0.0164 seconds
禁用表
hbase(main):042:0> disable 'test' Took 1.2551 seconds
再次删除表
hbase(main):043:0> drop 'test' Took 0.4710 seconds
查看表是否存在
hbase(main):044:0> list 'test' TABLE 0 row(s) Took 0.0108 seconds => []
返回结果为空,表示删除成功
断开连接
quit/exit命令:退出客户端
hbase(main):045:0> quit
[root@hbase111 hbase-2.2.3]#