1、连接HBase:hbase shell
[root@localhost bin]# hbase shell
2018-09-13 22:23:27,767 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 2.1.0, re1673bb0bbfea21d6e5dba73e013b09b8b49b89b, Tue Jul 10 17:26:48 CST 2018
Took 0.0074 seconds
Ignoring executable-hooks-1.3.2 because its extensions are not built. Try: gem pristine executable-hooks --version 1.3.2
Ignoring gem-wrappers-1.3.2 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.3.2
2.3.3 :001 >
2、展示帮助 :help
2.3.3 :001 > help
HBase Shell, version 2.1.0, re1673bb0bbfea21d6e5dba73e013b09b8b49b89b, Tue Jul 10 17:26:48 CST 2018
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
......
3、创建表:使用create命令创建一个新表,并且必须指出表名和ColumnFamily名(列族名)
2.3.3 :003 > create 'test','cf1'
Created table test
Took 1.1856 seconds
=> Hbase::Table - test
4、展示你的表信息:list
2.3.3 :004 > list
TABLE
test
1 row(s)
Took 0.0663 seconds
=> ["test"]
5、展示一个表的详细信息:describe
2.3.3 :005 > describe 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf1', 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', BLOCKCACHE => 'true
', BLOCKSIZE => '65536'}
1 row(s)
Took 0.1482 seconds
6、往表中存入数据:put
2.3.3 :006 > put 'test', 'row1', 'cf1', 'value1'
Took 0.0314 seconds
2.3.3 :007 > put 'test', 'row2', 'cf2', 'value2'
Took 0.0409 seconds
2.3.3 :008 > put 'test', 'row3', 'cf3', 'value3'
Took 0.0071 seconds
2.3.3 :009 >
一共插入了三条数据 ,第一次插入到row1行,cf1列,插入值为value1。以此类推。
7、扫描全表数据:scan
2.3.3 :009 > scan 'test'
ROW COLUMN+CELL
row1 column=cf1:, timestamp=1536849684484, value=value1
row2 column=cf2:, timestamp=1536849696135, value=value2
row3 column=cf3:, timestamp=1536849705775, value=value3
3 row(s)
Took 0.0650 seconds
8、根据row获取数据
2.3.3 :010 > get 'test', 'row1'
COLUMN CELL
cf1: timestamp=1536849684484, value=value1
1 row(s)
Took 0.0196 seconds
2.3.3 :011 >
9、删除表中数据:deleteall
2.3.3 :014 > scan 'test'
ROW COLUMN+CELL
row1 column=cf1:, timestamp=1536849684484, value=value1
row2 column=cf2:, timestamp=1536849696135, value=value2
row3 column=cf3:, timestamp=1536849705775, value=value3
3 row(s)
Took 0.0195 seconds
2.3.3 :015 > deleteall 'test','row2'
Took 0.0095 seconds
2.3.3 :016 > scan 'test'
ROW COLUMN+CELL
row1 column=cf1:, timestamp=1536849684484, value=value1
row3 column=cf3:, timestamp=1536849705775, value=value3
2 row(s)
Took 0.0104 seconds
2.3.3 :017 >
10、禁用表:disable
2.3.3 :002 > disable 'test'
Took 0.5635 seconds
11、删除表:drop 注意删除表前必须禁用表
2.3.3 :003 > drop 'test'
Took 0.5269 seconds