在你安裝的隨意臺服務器節點上,執行命令:hbase shell,會進入到你的 hbase shell 客 戶端html
[hadoop@hadoop1 ~]$ hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/home/hadoop/apps/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/home/hadoop/apps/hadoop-2.7.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017 hbase(main):001:0>
說明,先看一下提示。實際上是不是有一句很重要的話:shell
HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell
講述了怎麼得到幫助,怎麼退出客戶端express
help 獲取幫助服務器
help:獲取全部命令提示app
help "dml" :獲取一組命令的提示ide
help "put" :獲取一個單獨命令的提示幫助oop
exit 退出 hbase shell 客戶端this
關於表的操做包括(建立create,查看錶列表list。查看錶的詳細信息desc,刪除表drop,清空表truncate,修改表的定義alter)spa
能夠輸入如下命令進行查看幫助命令命令行
hbase(main):001:0> help 'create'
1 hbase(main):001:0> help 'create' 2 Creates a table. Pass a table name, and a set of column family 3 specifications (at least one), and, optionally, table configuration. 4 Column specification can be a simple string (name), or a dictionary 5 (dictionaries are described below in main help output), necessarily 6 including NAME attribute. 7 Examples: 8 9 Create a table with namespace=ns1 and table qualifier=t1 10 hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5} 11 12 Create a table with namespace=default and table qualifier=t1 13 hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'} 14 hbase> # The above in shorthand would be the following: 15 hbase> create 't1', 'f1', 'f2', 'f3' 16 hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true} 17 hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}} 18 19 Table configuration options can be put at the end. 20 Examples: 21 22 hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40'] 23 hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40'] 24 hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe' 25 hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' } 26 hbase> # Optionally pre-split the table into NUMREGIONS, using 27 hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname) 28 hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'} 29 hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}} 30 hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1} 31 32 You can also keep around a reference to the created table: 33 34 hbase> t1 = create 't1', 'f1' 35 36 Which gives you a reference to the table named 't1', on which you can then 37 call methods. 38 hbase(main):002:0>
能夠看到其中一條提示
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
其中t1是表名,f1,f2,f3是列簇的名,如:
hbase(main):002:0> create 'myHbase',{NAME => 'myCard',VERSIONS => 5} 0 row(s) in 3.1270 seconds => Hbase::Table - myHbase hbase(main):003:0>
建立了一個名爲myHbase的表,表裏面有1個列簇,名爲myCard,保留5個版本信息
能夠輸入如下命令進行查看幫助命令
hbase(main):003:0> help 'list' List all tables in hbase. Optional regular expression parameter could be used to filter the output. Examples: hbase> list hbase> list 'abc.*' hbase> list 'ns:abc.*' hbase> list 'ns:.*' hbase(main):004:0>
直接輸入list進行查看
hbase(main):004:0> list TABLE myHbase 1 row(s) in 0.0650 seconds => ["myHbase"] hbase(main):005:0>
只有一條結果,就是剛剛建立的表myHbase
一個大括號,就至關於一個列簇。
hbase(main):006:0> desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true' , BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.2160 seconds hbase(main):007:0>
hbase(main):007:0> alter 'myHbase', NAME => 'myInfo'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.0690 seconds
hbase(main):008:0> desc 'myHbase'
Table myHbase is ENABLED
myHbase
COLUMN FAMILIES DESCRIPTION
{NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true'
, BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true'
, BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.0420 seconds
hbase(main):009:0>
hbase(main):009:0> alter 'myHbase', NAME => 'myCard', METHOD => 'delete' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.1920 seconds hbase(main):010:0> desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true' , BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0290 seconds hbase(main):011:0>
刪除一個列簇也能夠執行如下命令
alter 'myHbase', 'delete' => 'myCard'
hbase(main):011:0> alter 'myHbase', {NAME => 'hehe'}, {NAME => 'myInfo', METHOD => 'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 3.8260 seconds hbase(main):012:0> desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'hehe', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DAT A_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0410 seconds hbase(main):013:0>
hbase(main):013:0> truncate 'myHbase' Truncating 'myHbase' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in 3.6760 seconds hbase(main):014:0>
hbase(main):014:0> drop 'myHbase' ERROR: Table myHbase 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):015:0>
直接刪除表會報錯,根據提示須要先停用表
hbase(main):015:0> disable 'myHbase' 0 row(s) in 2.2620 seconds hbase(main):016:0> drop 'myHbase' 0 row(s) in 1.2970 seconds hbase(main):017:0> list TABLE 0 row(s) in 0.0110 seconds => [] hbase(main):018:0>
關於數據的操做(增put,刪delete,查get + scan, 改==變相的增長)
建立 user 表,包含 info、data 兩個列簇
hbase(main):018:0> create 'user_info',{NAME=>'base_info',VERSIONS=>3 },{NAME=>'extra_info',VERSIONS=>1 } 0 row(s) in 4.2670 seconds => Hbase::Table - user_info hbase(main):019:0>
查看幫助,須要傳入表名,rowkey,列簇名、值等
hbase(main):019:0> help 'put' Put a cell 'value' at specified table/row/column and optionally timestamp coordinates. To put a cell value into table 'ns1:t1' or 't1' at row 'r1' under column 'c1' marked with the time 'ts1', do: hbase> put 'ns1:t1', 'r1', 'c1', 'value' hbase> put 't1', 'r1', 'c1', 'value' hbase> put 't1', 'r1', 'c1', 'value', ts1 hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}} hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}} hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'} The same commands also can be run on a table reference. Suppose you had a reference t to table 't1', the corresponding command would be: hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}} hbase(main):020:0>
向 user 表中插入信息,row key 爲 user0001,列簇 base_info 中添加 name 列標示符,值爲 zhangsan1
hbase(main):020:0> put 'user_info', 'user0001', 'base_info:name', 'zhangsan1' 0 row(s) in 0.2900 seconds hbase(main):021:0>
此處能夠多添加幾條數據
put 'user_info', 'zhangsan_20150701_0001', 'base_info:name', 'zhangsan1' put 'user_info', 'zhangsan_20150701_0002', 'base_info:name', 'zhangsan2' put 'user_info', 'zhangsan_20150701_0003', 'base_info:name', 'zhangsan3' put 'user_info', 'zhangsan_20150701_0004', 'base_info:name', 'zhangsan4' put 'user_info', 'zhangsan_20150701_0005', 'base_info:name', 'zhangsan5' put 'user_info', 'zhangsan_20150701_0006', 'base_info:name', 'zhangsan6' put 'user_info', 'zhangsan_20150701_0007', 'base_info:name', 'zhangsan7' put 'user_info', 'zhangsan_20150701_0008', 'base_info:name', 'zhangsan8' put 'user_info', 'zhangsan_20150701_0001', 'base_info:age', '21' put 'user_info', 'zhangsan_20150701_0002', 'base_info:age', '22' put 'user_info', 'zhangsan_20150701_0003', 'base_info:age', '23' put 'user_info', 'zhangsan_20150701_0004', 'base_info:age', '24' put 'user_info', 'zhangsan_20150701_0005', 'base_info:age', '25' put 'user_info', 'zhangsan_20150701_0006', 'base_info:age', '26' put 'user_info', 'zhangsan_20150701_0007', 'base_info:age', '27' put 'user_info', 'zhangsan_20150701_0008', 'base_info:age', '28' put 'user_info', 'zhangsan_20150701_0001', 'extra_info:Hobbies', 'music' put 'user_info', 'zhangsan_20150701_0002', 'extra_info:Hobbies', 'sport' put 'user_info', 'zhangsan_20150701_0003', 'extra_info:Hobbies', 'music' put 'user_info', 'zhangsan_20150701_0004', 'extra_info:Hobbies', 'sport' put 'user_info', 'zhangsan_20150701_0005', 'extra_info:Hobbies', 'music' put 'user_info', 'zhangsan_20150701_0006', 'extra_info:Hobbies', 'sport' put 'user_info', 'zhangsan_20150701_0007', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0001', 'base_info:name', 'baiyc1' put 'user_info', 'baiyc_20150716_0002', 'base_info:name', 'baiyc2' put 'user_info', 'baiyc_20150716_0003', 'base_info:name', 'baiyc3' put 'user_info', 'baiyc_20150716_0004', 'base_info:name', 'baiyc4' put 'user_info', 'baiyc_20150716_0005', 'base_info:name', 'baiyc5' put 'user_info', 'baiyc_20150716_0006', 'base_info:name', 'baiyc6' put 'user_info', 'baiyc_20150716_0007', 'base_info:name', 'baiyc7' put 'user_info', 'baiyc_20150716_0008', 'base_info:name', 'baiyc8' put 'user_info', 'baiyc_20150716_0001', 'base_info:age', '21' put 'user_info', 'baiyc_20150716_0002', 'base_info:age', '22' put 'user_info', 'baiyc_20150716_0003', 'base_info:age', '23' put 'user_info', 'baiyc_20150716_0004', 'base_info:age', '24' put 'user_info', 'baiyc_20150716_0005', 'base_info:age', '25' put 'user_info', 'baiyc_20150716_0006', 'base_info:age', '26' put 'user_info', 'baiyc_20150716_0007', 'base_info:age', '27' put 'user_info', 'baiyc_20150716_0008', 'base_info:age', '28' put 'user_info', 'baiyc_20150716_0001', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0002', 'extra_info:Hobbies', 'sport' put 'user_info', 'baiyc_20150716_0003', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0004', 'extra_info:Hobbies', 'sport' put 'user_info', 'baiyc_20150716_0005', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0006', 'extra_info:Hobbies', 'sport' put 'user_info', 'baiyc_20150716_0007', 'extra_info:Hobbies', 'music' put 'user_info', 'baiyc_20150716_0008', 'extra_info:Hobbies', 'sport'
獲取 user 表中 row key 爲 user0001 的全部信息
hbase(main):022:0> get 'user_info', 'user0001' COLUMN CELL base_info:name timestamp=1522320801670, value=zhangsan1 1 row(s) in 0.1310 seconds hbase(main):023:0>
獲取user表中row key爲rk0001,info列簇的全部信息
hbase(main):025:0> get 'user_info', 'rk0001', 'base_info' COLUMN CELL base_info:name timestamp=1522321247732, value=zhangsan 1 row(s) in 0.0320 seconds hbase(main):026:0>
查詢user_info表中的全部信息
hbase(main):026:0> scan 'user_info' ROW COLUMN+CELL rk0001 column=base_info:name, timestamp=1522321247732, value=zhangsan user0001 column=base_info:name, timestamp=1522320801670, value=zhangsan1 2 row(s) in 0.0970 seconds hbase(main):027:0>
查詢user_info表中列簇爲base_info的信息
hbase(main):027:0> scan 'user_info', {COLUMNS => 'base_info'} ROW COLUMN+CELL rk0001 column=base_info:name, timestamp=1522321247732, value=zhangsan user0001 column=base_info:name, timestamp=1522320801670, value=zhangsan1 2 row(s) in 0.0620 seconds hbase(main):028:0>
刪除user_info表row key爲rk0001,列標示符爲base_info:name的數據
hbase(main):028:0> delete 'user_info', 'rk0001', 'base_info:name' 0 row(s) in 0.0780 seconds hbase(main):029:0> scan 'user_info', {COLUMNS => 'base_info'} ROW COLUMN+CELL user0001 column=base_info:name, timestamp=1522320801670, value=zhangsan1 1 row(s) in 0.0530 seconds hbase(main):030:0>