进入hbase shell命令行:hbase shell
[hadoop@hdp01 hbase]$ hbase shell
2018-01-24 21:56:20,226 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.98.11-hadoop2, r6e6cf74c1161035545d95921816121eb3a516fe0, Tue Mar 3 00:23:49 PST 2015
hbase(main):001:0>
帮助命令:
help
hbase(main):001:0> help
HBase Shell, version 0.98.11-hadoop2, r6e6cf74c1161035545d95921816121eb3a516fe0, Tue Mar 3 00:23:49 PST 2015
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: 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, 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, incr, put, scan, truncate, truncate_preserve
Group name: tools
Commands: assign, balance_switch, balancer, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump
Group name: replication
Commands: add_peer, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, set_peer_tableCFs, show_peer_tableCFs
Group name: snapshots
Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot
Group name: security
Commands: grant, revoke, user_permission
Group name: visibility labels
Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility
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
hbase(main):002:0>
查看当前hbase版本号
hbase(main):010:0> version
0.98.11-hadoop2, r6e6cf74c1161035545d95921816121eb3a516fe0, Tue Mar 3 00:23:49 PST 2015
创建一个数据表:
create
hbase(main):001:0> create 'member','member_id','address','info'
2018-01-24 22:04:21,265 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
0 row(s) in 25.2310 seconds
=> Hbase::Table - member
hbase(main):002:0>
查看当前有多少表:
list
hbase(main):002:0> list
TABLE
member
1 row(s) in 0.1190 seconds
=> ["member"]
hbase(main):003:0>
查看表结构:
describe
hbase(main):003:0> describe 'member'
Table member is ENABLED
member
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',
VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS =
> 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VER
SIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => '
FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'member_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0'
, VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS
=> 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
3 row(s) in 0.7420 seconds
hbase(main):004:0>
使数据表disable(一般要编辑某个表的时候要先使表格
disable(失效)):
disable
hbase(main):004:0> disable 'member'
0 row(s) in 1.7460 seconds
激活数据表
(一般要编辑某个表后要激活表格,才能继续其他操作
):
enable
hbase(main):007:0> enable 'member'
0 row(s) in 1.7110 seconds
删除表中的一个列:
hbase(main):004:0> disable 'member'
0 row(s) in 1.7460 seconds
hbase(main):005:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 3.3320 seconds
hbase(main):006:0> describe 'member'
Table member is DISABLED
member
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',
VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS =
> 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VER
SIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => '
FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
2 row(s) in 0.1390 seconds
hbase(main):007:0>
查看表格是不是已存在: exists
hbase(main):010:0> exists 'member'
Table member does exist
0 row(s) in 0.0940 seconds
hbase(main):011:0>
检查表是不是处于激活状态:
is_enabled
hbase(main):012:0> is_enabled 'member'
true
0 row(s) in 0.0290 seconds
hbase(main):013:0>
查看表是不是处于disabled状态:is_disabled
hbase(main):013:0> is_disabled 'member'
false
0 row(s) in 0.0690 seconds
hbase(main):014:0>
删除表: drop
hbase(main):015:0> disable 'member'
0 row(s) in 1.3630 seconds
hbase(main):016:0> drop 'member'
0 row(s) in 1.4680 seconds
hbase(main):017:0> list
TABLE
0 row(s) in 0.0080 seconds
=> []
hbase(main):018:0>
向表里添加数据:
put
hbase(main):020:0> put 'member','djt','info:age','28'
0 row(s) in 1.0710 seconds
hbase(main):021:0> put 'member','djt','info:birthday','1988-12-12'
0 row(s) in 0.1580 seconds
hbase(main):022:0> put 'member','djt','info:company','company01'
0 row(s) in 0.0090 seconds
hbase(main):023:0> put 'member','djt','address:country','china'
0 row(s) in 0.0080 seconds
hbase(main):024:0> put 'member','djt','address:province','beijing'
0 row(s) in 0.0070 seconds
hbase(main):025:0> put 'member','djt','address:city','beijing'
0 row(s) in 0.0260 seconds
hbase(main):026:0>
扫描查询表内所有数据:
scan
hbase(main):026:0> scan 'member'
ROW COLUMN+CELL
djt column=address:city, timestamp=1516803716549, value=beijing
djt column=address:country, timestamp=1516803645769, value=china
djt column=address:province, timestamp=1516803691890, value=beijing
djt column=info:age, timestamp=1516803481711, value=28
djt column=info:birthday, timestamp=1516803528489, value=1988-12-12
djt column=info:company, timestamp=1516803589217, value=company01
1 row(s) in 0.3010 seconds
hbase(main):027:0>
获取
查询表内指定数据:
get
获取一个Row Key的所有数据
hbase(main):027:0> get 'member','djt'
COLUMN CELL
address:city timestamp=1516803716549, value=beijing
address:country timestamp=1516803645769, value=china
address:province timestamp=1516803691890, value=beijing
info:age timestamp=1516803481711, value=28
info:birthday timestamp=1516803528489, value=1988-12-12
info:company timestamp=1516803589217, value=company01
6 row(s) in 0.0460 seconds
hbase(main):028:0>
获取一个Row Key,一个列簇的所有数据
hbase(main):028:0> get 'member','djt','info'
COLUMN CELL
info:age timestamp=1516803481711, value=28
info:birthday timestamp=1516803528489, value=1988-12-12
info:company timestamp=1516803589217, value=company01
3 row(s) in 0.0120 seconds
hbase(main):029:0>
获取一个Row Key,一个列簇中某一列的所有数据
hbase(main):029:0> get 'member','djt','info:company'
COLUMN CELL
info:company timestamp=1516803589217, value=company01
1 row(s) in 0.0960 seconds
hbase(main):030:0>
更新一条数据:
put
hbase(main):031:0> put 'member','djt','info:age','30'
0 row(s) in 0.0100 seconds
hbase(main):032:0> get 'member','djt'
COLUMN CELL
address:city timestamp=1516803716549, value=beijing
address:country timestamp=1516803645769, value=china
address:province timestamp=1516803691890, value=beijing
info:age timestamp=1516804281881, value=30
info:birthday timestamp=1516803528489, value=1988-12-12
info:company timestamp=1516803589217, value=company01
6 row(s) in 0.0180 seconds
删除列簇的其中一列:
delete
hbase(main):034:0> delete 'member','djt','info:age'
0 row(s) in 0.2420 seconds
hbase(main):035:0> get 'member','djt'
COLUMN CELL
address:city timestamp=1516803716549, value=beijing
address:country timestamp=1516803645769, value=china
address:province timestamp=1516803691890, value=beijing
info:birthday timestamp=1516803528489, value=1988-12-12
info:company timestamp=1516803589217, value=company01
5 row(s) in 0.0200 seconds
统计表中总行数:
count
hbase(main):036:0> count 'member'
1 row(s) in 0.2530 seconds
=> 1
清空表中内容: truncate
hbase(main):037:0> truncate 'member'
Truncating 'member' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 9.8870 seconds
hbase(main):038:0> get 'member','djt'
COLUMN CELL
0 row(s) in 0.5020 seconds
hbase(main):039:0>