HBase Shell基本操作

首先启动hadoop集群与hbase服务
start-all.sh
hbase-1.1.3/bin/start-hbase.sh
接下来使用hbase shell命令来连接正在运行的Hbase实例,该命令位于HBase安装包下的bin/目录
hbase-1.1.3/bin/hbase shell

查看HBase状态
status

显示HBase Shell的基本使用信息
help

HBase Shell, version 1.4.10, r76ab087819fe82ccf6f531096e18ad1bed079651, Wed Jun 5 16:48:11 PDT 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_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', "keyx03x3fxcd"
hbase> get 't1', "key032311"
hbase> put 't1', "testxefxff", 'f1:', "x01x33x40"

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


查看有哪些表
list

退出HBase Shell
quit


数据定义(DDL)操作:

使用create命令来创建一个新的表。在创建的时候,必须指定表名(test)和列族名(cf)。
create 'test', 'cf'

列举表信息
list 'test'

获取表描述
describe 'test'

检查表是否存在
exists 'test'

清空表数据
truncate 'test'

禁用一个表
disable 'test'
重新启用表
enable 'test'

删除表。删除表之前,需要先disable表
drop 'test'


数据管理(DML)操作:

使用put命令,将数据插入表中
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:a', 'value2'
put 'test', 'row3', 'cf:a', 'value3'

一次性扫描全表数据
scan 'test'
获取一行数据
get 'test', 'row1'

删除数据:
删除一个单元格,必须指定列名
delete '<table name>', '<row>', ‘<family:column>’,‘<time stamp>’
删除一行
deleteall '<table name>', '<row>'

实验使用实验楼环境:
https://www.shiyanlou.com/courses/37/labs/756/document

phoenix使用:
phoenix/bin/sqlline.py localhost:2181
./psql.py localhost:2181 ./WEB_STAT.sql ./WEB_STAT.csv

原文地址:https://www.cnblogs.com/mycd/p/7814680.html