目录
打错命令,按ctrl+Backspace
1.启动hbase
2.关闭hbase
3. HBase Shell
4.help命令
5.查看集群状态status
6.创建表
7.插入数据
8.查询数据
9.扫描列簇
10.扫描列簇的指定列
11.扫描指定范围
12.查看表结构
13.更新指定字段的数据
14.查看指定行的数据
15.查看指定列族的列的数据
16.查看行数
17.删除某 rowkey 行键的全部数据:
18.删除某 rowkey 的某一列数据:
19.列举所有表list
20.表是否存在exists
21.启用表enable和禁用表disable
22.清空表数据
23.删除表
start-hbase.sh
stop-hbase.sh
是官方提供的一组命令,用于操作HBase。如果配置了HBase的环境变量了,就可以输入hbase shell 命令进入命令行。
hbase shell
可以通过 help '命名名称'来查看命令行的具体使用,包括命令的作用和用法。
通过help ‘hbase’ 命名来查看hbase shell 支持的所有命令,hbase将命令进行分组,其中ddl、dml使用较多。
hbase(main):002:0> help 'hbase'
ERROR: Invalid command or command group name: hbase
HBase Shell, version 1.4.13, r38bf65a22b7e9320f07aeb27677e4533b9a77ef4, Sun Feb 23 02:06:36 PST 2020
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
hbase(main):003:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 7.0000 average load
#语法
create '表名','列簇名'
#例如
hbase(main):014:0> create 'year','info'
0 row(s) in 1.2980 seconds
=> Hbase::Table - year
#语法
put '表名','行键','列簇名','值'
#例如
# 第一行数据
hbase(main):015:0> put 'year', '1001', 'info:id', '1'
0 row(s) in 0.1320 seconds
hbase(main):016:0> put 'year', '1001', 'info:name', '张三'
0 row(s) in 0.0070 seconds
hbase(main):017:0> put 'year', '1001', 'info:age', '28'
0 row(s) in 0.0080 seconds
# 第二行数据
hbase(main):026:0> put 'year', '1002', 'info:id', '2'
0 row(s) in 0.0100 seconds
hbase(main):027:0> put 'year', '1002', 'info:name', '李四'
0 row(s) in 0.0050 seconds
hbase(main):028:0> put 'year', '1002', 'info:age', '20'
0 row(s) in 0.0040 seconds
# 第三行数据
hbase(main):029:0> put 'year', '1003', 'info:id', '3'
0 row(s) in 0.0120 seconds
hbase(main):030:0> put 'year', '1003', 'info:name', 'wangwu'
0 row(s) in 0.0070 seconds
hbase(main):031:0> put 'year', '1003', 'info:age', '16'
0 row(s) in 0.0140 seconds
scan '表名'
hbase(main):032:0> scan 'year'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650518056828, value=28
1001 column=info:id, timestamp=1650518051442, value=1
1001 column=info:name, timestamp=1650518051501, value=\xE5\xBC\xA0\xE4\xB8\x89
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B #中文编码
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
3 row(s) in 0.0430 seconds
# 语法
scan '表名', {COLUMN=>'列族名'}
# 例如
hbase(main):033:0> scan 'year',{COLUMN=>'info'}
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650518056828, value=28
1001 column=info:id, timestamp=1650518051442, value=1
1001 column=info:name, timestamp=1650518051501, value=\xE5\xBC\xA0\xE4\xB8\x89
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
3 row(s) in 0.0360 seconds
# 语法
scan '表名', {COLUMN=>'列族名:列名'}
#例如
hbase(main):034:0> scan 'year',{COLUMN=>'info:age'}
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650518056828, value=28
1002 column=info:age, timestamp=1650518373828, value=20
1003 column=info:age, timestamp=1650518386062, value=16
3 row(s) in 0.0310 seconds
hbase(main):035:0> scan 'year',{STARTROW => '1001', STOPROW => '1003'} #前闭后开
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650518056828, value=28
1001 column=info:id, timestamp=1650518051442, value=1
1001 column=info:name, timestamp=1650518051501, value=\xE5\xBC\xA0\xE4\xB8\x89
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
2 row(s) in 0.0310 seconds
hbase(main):036:0> scan 'year',{STARTROW => '1001'}
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650518056828, value=28
1001 column=info:id, timestamp=1650518051442, value=1
1001 column=info:name, timestamp=1650518051501, value=\xE5\xBC\xA0\xE4\xB8\x89
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
3 row(s) in 0.0620 seconds
#语法
descride '表名'
#例如
hbase(main):037:0> describe 'year'
Table year is ENABLED
year
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE
', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.0450 seconds
#语法
put '表名','行键','列簇名','值'
#例如
hbase(main):038:0> put 'year', '1001', 'info:id', '1'
0 row(s) in 0.0210 seconds
hbase(main):039:0> put 'year', '1001', 'info:name', 'zhangsan'
0 row(s) in 0.0120 seconds
hbase(main):040:0> put 'year', '1001', 'info:age', '22'
0 row(s) in 0.0080 seconds
hbase(main):041:0> scan 'year'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1650519485027, value=22
1001 column=info:id, timestamp=1650519483672, value=1
1001 column=info:name, timestamp=1650519483706, value=zhangsan
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
3 row(s) in 0.0290 seconds
#语法
get '表名','行键'
#例如
hbase(main):042:0> get 'year','1001'
COLUMN CELL
info:age timestamp=1650519485027, value=22
info:id timestamp=1650519483672, value=1
info:name timestamp=1650519483706, value=zhangsan
1 row(s) in 0.0310 seconds
#语法
get '表名','行键','列簇名'
#例如
hbase(main):043:0> get 'year','1001','info:age'
COLUMN CELL
info:age timestamp=1650519485027, value=22
1 row(s) in 0.0110 seconds
#语法
count '表名'
#例如
hbase(main):044:0> count 'year'
3 row(s) in 0.0120 seconds
=> 3
#语法
deleteall '表名','行键'
#例如
hbase(main):045:0> deleteall 'year','1001'
0 row(s) in 0.0520 seconds
hbase(main):046:0> scan 'year'
ROW COLUMN+CELL
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:id, timestamp=1650518373023, value=2
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
2 row(s) in 0.0120 seconds
#语法
deleteall '表名','行键','列簇名'
#例如
hbase(main):049:0> deleteall 'year','1002','info:id'
0 row(s) in 0.0050 seconds
hbase(main):050:0> scan 'year'
ROW COLUMN+CELL
1002 column=info:age, timestamp=1650518373828, value=20
1002 column=info:name, timestamp=1650518373053, value=\xE6\x9D\x8E\xE5\x9B\x9B
1003 column=info:age, timestamp=1650518386062, value=16
1003 column=info:id, timestamp=1650518382621, value=3
1003 column=info:name, timestamp=1650518382650, value=wangwu
2 row(s) in 0.0160 seconds
hbase(main):051:0> list
TABLE
year
1 row(s) in 0.0110 seconds
=> ["year"]
# 语法
exists '表名'
#例如
hbase(main):052:0> exists 'year'
Table year does exist
0 row(s) in 0.0110 seconds
通过enable和disable来启用/禁用这个表,相应的可以通过is_enabled和is_disabled来检查表是否被禁用。
# 语法
enable '表名'
is_enabled '表名'
disable '表名'
is_disabled '表名'
#例如
hbase(main):053:0> enable 'year'
0 row(s) in 0.0190 seconds
hbase(main):054:0> is_enabled 'year'
true
0 row(s) in 0.0100 seconds
hbase(main):055:0>
hbase(main):056:0* disable 'year'
0 row(s) in 2.2670 seconds
hbase(main):057:0> is_disabled 'year'
true
0 row(s) in 0.0320 seconds
#语法
先禁用表
才能清空数据
#例如
disable 'year'
turncate 'year'
#语法
先禁用表
才能删除表
#例如
disable 'year'
drop 'year'