hbase(main):030:0> help HBase Shell, version 0.96.1.1-hadoop1, rUnknown, Tue Dec 17 11:52:14 PST 2013 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: 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, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump Group name: replication Commands: add_peer, disable_peer, enable_peer, list_peers, list_replicated_tables, remove_peer Group name: snapshot Commands: clone_snapshot, delete_snapshot, list_snapshots, rename_snapshot, restore_snapshot, snapshot Group name: security Commands: grant, revoke, user_permission 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/docs/current/book.html
1、进入shell,进入hbase的shell界面
hbase shell HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.96.1.1-hadoop1, rUnknown, Tue Dec 17 11:52:14 PST 2013
2、查看hbase的状态
status 1 servers, 0 dead, 2.0000 average load
3、查看hbase的版本
version 0.96.1.1-hadoop1, rUnknown, Tue Dec 17 11:52:14 PST 2013
4、创建表
1、创建表 hbase(main):004:0> create 'tab1','name','age','addr' 0 row(s) in 1.5040 seconds => Hbase::Table - tab1 tab1:表名 'name','age','addr':3个列族 创建新表至少要有一个列族。 2、查看表 (1)list TABLE tab1 (2)describe 'tab1' DESCRIPTION ENABLED 'tab1', {NAME => 'addr', DATA_BLOCK_ENCODING => 'NO true NE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0' , VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSI ONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'fa lse', BLOCKCACHE => 'true'}, {NAME => 'age', DATA_B LOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPL ICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647' , KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '6553 6', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {N AME => 'name', DATA_BLOCK_ENCODING => 'NONE', BLOOM FILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0' , TTL => '2147483647', KEEP_DELETED_CELLS => 'false ', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOC KCACHE => 'true'} 1 row(s) in 0.1410 seconds
3、添加数据 put 'tab1','row2','age:age','24' 0 row(s) in 0.0270 seconds 注:tab1:表名,row2:row key,'age:age':列名和列的key,24列的value
5、查看表
(1)查看全部记录
scan 'tab1' ROW COLUMN+CELL row1 column=name:name, timestamp=1391849407402, value=ru row2 column=age:age, timestamp=1391849930953, value=24
(2)查看部分记录
根据row key查询记录 get 'tab1','ruge' COLUMN CELL name:mingzi timestamp=1391852952026, value=ru name:name timestamp=1391853119913, value=ruge name:xingming timestamp=1391852798192, value=ruge
注:tab1:表名,ruge:row key
根据row key,和列族查询记录 get 'tab1','row2','age' COLUMN CELL age:age timestamp=1391849930953, value=24
注:tab1:表名,row2:row key, age:列族
根据row key,列族和列名查询你一条记录 get 'tab1','ruge','name:xingming' COLUMN CELL name:xingming timestamp=1391852798192, value=ruge
6、修改表记录
put 'tab1','ruge','age:nianling','21'
7、删除记录
(1)删除一条记录
delete 'tab1','ruge','age:nianling'
注:age:nianling':表示一列
(2)删除一行记录
deleteall 'tab1','row1'
row1:表示行键,这样会把这个行键的所有记录都删除
8、查看表有多少行
scan 'tab1'
ROW COLUMN+CELL
row2 column=age:age, timestamp=1391849930953, value=24
ruge column=age:age_nl, timestamp=1391936937906, value=25
ruge column=name:mingzi, timestamp=1391852952026, value=ru
ruge column=name:name, timestamp=1391853119913, value=ruge
ruge column=name:xingming, timestamp=1391852798192, value=ruge
这个表有2行
使用count命令查看
count 'tab1' 2 row(s) in 0.0860 seconds
9、清空表
truncate 'test' Truncating 'test' table (it may take a while): - Disabling table... - Dropping table... - Creating table...