hbase shell
general命令
hbase(main):010:0> version
1.2.0-cdh5.8.3, rUnknown, Wed Oct 12 20:33:08 PDT 2016
hbase(main):011:0> whoami
hadoop (auth:SIMPLE)
groups: hadoop
hbase(main):012:0> status
1 active master, 0 backup masters, 3 servers, 0 dead, 2.6667 average load
ddl 命令
hbase(main):018:0> create 't2', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
0 row(s) in 88.2960 seconds
=> Hbase::Table - t2
hbase(main):019:0> describe 't2'
Table t2 is ENABLED
t2
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', 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 => 'f2', 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 => 'f3', 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.1560 seconds
hbase(main):020:0> exists 't2'
Table t2 does exist
0 row(s) in 0.0300 seconds
hbase(main):021:0> is_disabled 't2'
false
0 row(s) in 0.0300 seconds
hbase(main):022:0> is_enabled 't2'
true
0 row(s) in 0.0290 seconds
hbase(main):023:0> alter 't2',{NAME=>'t_info',TTL=>'300'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.2300 seconds
hbase(main):024:0> desc 't2'
Table t2 is ENABLED
t2
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', 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 => 'f2', 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 => 'f3', 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 => 't_info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => '300 SECONDS (5 MINUTES)',
MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
4 row(s) in 0.0430 seconds
hbase(main):026:0> list
TABLE
t1
t2
tc
tc1
test
5 row(s) in 0.0110 seconds
=> ["t1", "t2", "tc", "tc1", "test"]
hbase(main):027:0> drop 't2'
ERROR: Table t2 is enabled. Disable it first.
Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
hbase(main):030:0> drop 't2'
ERROR: Table t2 is enabled. Disable it first.
Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
hbase(main):031:0> disable 't2'
0 row(s) in 2.3130 seconds
hbase(main):032:0> drop 't2'
0 row(s) in 1.3100 seconds
hbase(main):033:0> list
TABLE
t1
tc
tc1
test
4 row(s) in 0.0100 seconds
namespace相关命令
drop_namespace必需先删除namespace下所有表
hbase(main):054:0> list_namespace
NAMESPACE
default
hbase
tc
3 row(s) in 0.0120 seconds
hbase(main):055:0> create_namespace 'ns1'
0 row(s) in 0.0720 seconds
hbase(main):056:0> create 'ns1:t2',{NAME=>'t_info',TTL=>'300'}
0 row(s) in 38.2670 seconds
=> Hbase::Table - ns1:t2
hbase(main):057:0> list_namespace_tables 'ns1'
TABLE
t2
1 row(s) in 0.0160 seconds
hbase(main):058:0> describe_namespace 'ns1'
DESCRIPTION
{NAME => 'ns1'}
1 row(s) in 0.0070 seconds
hbase(main):059:0> drop_namespace 'ns1'
dml命令
hbase(main):001:0> put 't2','key1','t_info','123'
0 row(s) in 0.4240 seconds
hbase(main):002:0> put 't2','key2','t_info:age','30'
0 row(s) in 0.0130 seconds
hbase(main):003:0> get 't2','key1','t_info'
COLUMN CELL
t_info: timestamp=1505381725025, value=123
1 row(s) in 0.0330 seconds
hbase(main):004:0> scan 't2'
ROW COLUMN+CELL
key1 column=t_info:, timestamp=1505381725025, value=123
key2 column=t_info:age, timestamp=1505381730825, value=30
2 row(s) in 0.0880 seconds
hbase(main):005:0> count 't2'
2 row(s) in 0.0320 seconds
=> 2
hbase(main):007:0> delete 't2','key1','t_info'
0 row(s) in 0.0510 seconds
hbase(main):008:0> scan 't2'
ROW COLUMN+CELL
key2 column=t_info:age, timestamp=1505381730825, value=30
1 row(s) in 0.0120 seconds
hbase(main):009:0> truncate 't2'
Truncating 't2' table (it may take a while):
- Disabling table...
- Truncating table...
另一种表操作方法
hbase(main):012:0> tab = get_table 't'
0 row(s) in 0.0010 seconds
=> Hbase::Table - t
hbase(main):013:0> tab.put ‘r1’ ,’f’, ‘v’
0 row(s) in 0.0100 seconds
hbase(main):014:0> tab.scan
ROW COLUMN+CELL
r1 column=f:, timestamp=1378473876949, value=v
展示并删除t开头的表>
hbase(main):016 > tables = list(‘t.*’)
TABLE
t1 row(s) in 0.1040 seconds
hbase(main):017:0> tables.map { |t| disable t ; drop t}
0 row(s) in 2.2510 seconds
> [nil]
hbase hbck (检查)
hbase hbck -fix (修复)
hbase thrift start 启动thrift服务
后台启动关闭:
hbase-daemon.sh start thrift
hbase-daemon.sh stop thrift
前台启动hbase rest服务
bin/hbase rest start -p <port>
后台启动hbase服务
bin/hbase-daemon.sh start rest -p <port>
停止服务
bin/hbase-daemon.sh stop rest
不加端口的情况下,端口默认为8080