1.进入hbase shell 命令行
[hdfs@hadoopm106 ~]$ hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/hdp/3.1.4.0-315/phoenix/phoenix-5.0.0.3.1.4.0-315-server.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hdp/3.1.4.0-315/hadoop/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.2.3.1.4.0-315, r, Fri Aug 23 05:15:48 UTC 2019
Took 0.0015 seconds
2.帮助 help
hbase(main):027:0> help
HBase Shell, version 2.0.2.3.1.4.0-315, r, Fri Aug 23 05:15:48 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_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_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
3.查看命名空间
hbase(main):028:0> list_namespace
NAMESPACE
SYSTEM
TEST
applet_center
default
hbase
log_center
message_center
7 row(s)
Took 0.1432 seconds
4.创建表myHbase
hbase(main):036:0> create 'myHbase',{NAME => 'myCard',VERSIONS =>5}
Created table myHbase
Took 1.3105 seconds
=> Hbase::Table - myHbase
创建了一个名为myHbase的表,表里面有1个列簇,名为myCard,保留5个版本信息
5.查看表详细信息
hbase(main):046:0* desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myCard', VERSIONS => '5', 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', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOC
KCACHE => 'true', BLOCKSIZE => '65536'}
1 row(s)
Took 0.0280 seconds
一个大括号,就相当于一个列簇。
6.添加一个列族
hbase(main):047:0> alter 'myHbase', NAME => 'myInfo'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.3094 seconds
查看添加结果
hbase(main):051:0* desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myCard', VERSIONS => '5', 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', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOC
KCACHE => 'true', BLOCKSIZE => '65536'}
{NAME => 'myInfo', 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', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOC
KCACHE => 'true', BLOCKSIZE => '65536'}
2 row(s)
Took 0.0231 seconds
7.删除一个列族
hbase(main):055:0* alter 'myHbase', NAME => 'myCard',METHOD => 'delete'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.1932 seconds
hbase(main):056:0>
hbase(main):057:0* desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myInfo', 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', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOC
KCACHE => 'true', BLOCKSIZE => '65536'}
1 row(s)
Took 0.0273 seconds
8. 清空表数据
hbase(main):058:0> truncate 'myHbase'
Truncating 'myHbase' table (it may take a while):
Disabling table...
Truncating table...
Took 1.6431 seconds
9.删除表
hbase(main):059:0> drop 'myHbase'
ERROR: Table myHbase is enabled. Disable it first.
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
Took 0.0515 seconds
hbase(main):060:0> disable 'myHbase'
Took 0.7457 seconds
hbase(main):061:0> drop 'myHbase'
Took 0.2548 seconds
删除表之前需要对表进行disable
10.创建测试表进行写入put 和查询 get和删除delete
#创建测试表
hbase(main):063:0> create 'user_info',{NAME=>'base_info',VERSIONS=>3 }
Created table user_info
Took 1.2638 seconds
=> Hbase::Table - user_info
# 向 user 表中插入信息,row key 为 user0001,列簇 base_info 中添加 name 列标示符,值为 zhangsan1
hbase(main):064:0> put 'user_info', 'user0001', 'base_info:name', 'zhangsan1'
Took 0.3964 seconds
hbase(main):065:0> put 'user_info', 'user0001', 'base_info:age', '18'
Took 0.0262 seconds
#查询表user_info,rowkey 为user0001
hbase(main):066:0> get 'user_info', 'user0001'
COLUMN CELL
base_info:age timestamp=1703152248107, value=18
base_info:name timestamp=1703152237695, value=zhangsan1
1 row(s)
Took 0.2152 seconds
#扫表数据
hbase(main):067:0> scan 'user_info'
ROW COLUMN+CELL
user0001 column=base_info:age, timestamp=1703152248107, value=18
user0001 column=base_info:name, timestamp=1703152237695, value=zhangsan1
1 row(s)
Took 0.0648 seconds
#删除user_info表row key为user0001,列标示符为base_info:name的数据
hbase(main):070:0> delete 'user_info', 'user0001', 'base_info:name'
Took 0.0188 seconds
hbase(main):071:0> scan 'user_info'
ROW COLUMN+CELL
user0001 column=base_info:age, timestamp=1703152248107, value=18
1 row(s)
Took 0.0185 seconds
标签:info,shell,false,list,myHbase,命令,Hbase,main,hbase
From: https://www.cnblogs.com/whiteY/p/17919811.html