一、進入HBase命令行
在你安裝的隨意台服務器節點上,執行命令:hbase shell,會進入到你的 hbase shell 客 戶端
[admin@node21 ~]$ hbase shell SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hadoop-2.7.6/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
1.8.7-p357 :001 >
說明,先看一下提示。其實是不是有一句很重要的話:
HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell
講述了怎么獲得幫助,怎么退出客戶端
help 獲取幫助
help:獲取所有命令提示
help "dml" :獲取一組命令的提示
help "put" :獲取一個單獨命令的提示幫助
exit 退出 hbase shell 客戶端
二、HBase表的操作
這些是關於HBase在表中操作的命令。
- create: 創建一個表。
- list: 列出HBase的所有表。
- disable: 禁用表。
- is_disabled: 驗證表是否被禁用。
- enable: 啟用一個表。
- is_enabled: 驗證表是否已啟用。
- describe: 提供了一個表的描述。
- alter: 改變一個表。
- exists: 驗證表是否存在。
- drop: 從HBase中刪除表。
- drop_all: 丟棄在命令中給出匹配“regex”的表。
- Java Admin API: 在此之前所有的上述命令,Java提供了一個通過API編程來管理實現DDL功能。在這個org.apache.hadoop.hbase.client包中有HBaseAdmin和HTableDescriptor 這兩個重要的類提供DDL功能。
關於表的操作包括(創建create,查看表列表list。查看表的詳細信息desc,刪除表drop,清空表truncate,修改表的定義alter)
1、創建表create
可以輸入以下命令進行查看幫助命令
1.8.7-p357 :001 > help 'create'
Creates a table. Pass a table name, and a set of column family specifications (at least one), and, optionally, table configuration. Column specification can be a simple string (name), or a dictionary (dictionaries are described below in main help output), necessarily including NAME attribute. Examples: Create a table with namespace=ns1 and table qualifier=t1 hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5} Create a table with namespace=default and table qualifier=t1 hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'} hbase> # The above in shorthand would be the following: hbase> create 't1', 'f1', 'f2', 'f3' hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true} hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}} Table configuration options can be put at the end. Examples: hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40'] hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40'] hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe' hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' } hbase> # Optionally pre-split the table into NUMREGIONS, using hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname) hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'} hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', REGION_REPLICATION => 2, CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand ' => 'true'}} hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1} You can also keep around a reference to the created table: hbase> t1 = create 't1', 'f1' Which gives you a reference to the table named 't1', on which you can then call methods. 1.8.7-p357 :002 >
可以看到其中一條提示
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
其中t1是表名,f1,f2,f3是列簇的名,如:
1.8.7-p357 :002 > create 'myHbase',{NAME => 'myCard',VERSIONS => 5} 0 row(s) in 9.1260 seconds => Hbase::Table - myHbase 1.8.7-p357 :003 >
創建了一個名為myHbase的表,表里面有1個列簇,名為myCard,保留5個版本信息
2、查看表列表list
可以輸入以下命令進行查看幫助命令
1.8.7-p357 :003 > 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:.*' 1.8.7-p357 :004 >
直接輸入list進行查看
1.8.7-p357 :004 > list TABLE myHbase 1 row(s) in 0.0610 seconds => ["myHbase"] 1.8.7-p357 :005 >
只有一條結果,就是剛剛創建的表myHbase
3、查看表詳細信息desc
一個大括號,就相當於一個列簇。
1.8.7-p357 :005 > desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRES SION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.5470 seconds 1.8.7-p357 :006 >
4、修改表定義alter
添加一個列簇
1.8.7-p357 :006 > alter 'myHbase', NAME => 'myInfo' Updating all regions with the new schema... 0/1 regions updated. 1/1 regions updated. Done. 0 row(s) in 3.6430 seconds 1.8.7-p357 :007 > desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRES SION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} {NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRES SION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 2 row(s) in 0.1080 seconds 1.8.7-p357 :008 >
刪除一個列簇
1.8.7-p357 :008 > alter 'myHbase', NAME => 'myCard', METHOD => 'delete' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.7110 seconds 1.8.7-p357 :009 > desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRES SION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0510 seconds 1.8.7-p357 :010 >
刪除一個列簇也可以執行以下命令
alter 'myHbase', 'delete' => 'myCard'
添加列簇hehe同時刪除列簇myInfo
1.8.7-p357 :010 > 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... 0/1 regions updated. 1/1 regions updated. Done. 0 row(s) in 5.5340 seconds 1.8.7-p357 :011 > desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'hehe', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSI ON => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0520 seconds 1.8.7-p357 :012 >
5、truncate清空表
1.8.7-p357 :012 > truncate 'myHbase' Truncating 'myHbase' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in 8.6040 seconds 1.8.7-p357 :013 >
6、刪除表drop
1.8.7-p357 :013 > 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' 1.8.7-p357 :014 >
直接刪除表會報錯,根據提示需要先停用表
1.8.7-p357 :014 > disable 'myHbase' 0 row(s) in 2.3470 seconds 1.8.7-p357 :015 > drop 'myHbase' 0 row(s) in 1.3850 seconds 1.8.7-p357 :016 > list TABLE 0 row(s) in 0.0110 seconds => [] 1.8.7-p357 :017 >
三、HBase表中數據的操作
- put: 把指定列在指定的行中單元格的值在一個特定的表。
- get: 取行或單元格的內容。
- delete: 刪除表中的單元格值。
- deleteall: 刪除給定行的所有單元格。
- scan: 掃描並返回表數據。
- count: 計數並返回表中的行的數目。
- truncate: 禁用,刪除和重新創建一個指定的表。
- Java client API: 在此之前所有上述命令,Java提供了一個客戶端API來實現DML功能,CRUD(創建檢索更新刪除)操作更多的是通過編程,在org.apache.hadoop.hbase.client包下。 在此包HTable 的 Put和Get是重要的類。
關於數據的操作(增put,刪delete,查get + scan, 改==變相的增加)
創建 user 表,包含 info、data 兩個列簇
1.8.7-p357 :017 > create 'user_info',{NAME=>'base_info',VERSIONS=>3 },{NAME=>'extra_info',VERSIONS=>1 } 0 row(s) in 4.3020 seconds => Hbase::Table - user_info 1.8.7-p357 :018 >
1、增put
查看幫助,需要傳入表名,rowkey,列簇名、值等
1.8.7-p357 :018 > 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'}} 1.8.7-p357 :019 >
向 user 表中插入信息,row key 為 user0001,列簇 base_info 中添加 name 列標示符,值為 zhangsan1
1.8.7-p357 :019 > put 'user_info', 'user0001', 'base_info:name', 'zhangsan1' 0 row(s) in 0.6590 seconds 1.8.7-p357 :020 >
此處可以多添加幾條數據

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'
2、查get + scan
help 'get'

1.8.7-p357 :074 > help 'get' Get row or cell contents; pass table name, row, and optionally a dictionary of column(s), timestamp, timerange and versions. Examples: hbase> get 'ns1:t1', 'r1' hbase> get 't1', 'r1' hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]} hbase> get 't1', 'r1', {COLUMN => 'c1'} hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4} hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"} hbase> get 't1', 'r1', 'c1' hbase> get 't1', 'r1', 'c1', 'c2' hbase> get 't1', 'r1', ['c1', 'c2'] hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}} hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']} hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'} hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1} Besides the default 'toStringBinary' format, 'get' also supports custom formatting by column. A user can define a FORMATTER by adding it to the column name in the get specification. The FORMATTER can be stipulated: 1. either as a org.apache.hadoop.hbase.util.Bytes method name (e.g, toInt, toString) 2. or as a custom class followed by method name: e.g. 'c(MyFormatterClass).format'. Example formatting cf:qualifier1 and cf:qualifier2 both as Integers: hbase> get 't1', 'r1' {COLUMN => ['cf:qualifier1:toInt', 'cf:qualifier2:c(org.apache.hadoop.hbase.util.Bytes).toInt'] } Note that you can specify a FORMATTER by column only (cf:qualifier). You cannot specify a FORMATTER for all columns of a column family. The same commands also can be run on a reference to a table (obtained via get_table or create_table). Suppose you had a reference t to table 't1', the corresponding commands would be: hbase> t.get 'r1' hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]} hbase> t.get 'r1', {COLUMN => 'c1'} hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']} hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1} hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4} hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4} hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"} hbase> t.get 'r1', 'c1' hbase> t.get 'r1', 'c1', 'c2' hbase> t.get 'r1', ['c1', 'c2'] hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'} hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1} 1.8.7-p357 :075 >
獲取 user 表中 row key 為 user0001 的所有信息
1.8.7-p357 :072 > get 'user_info', 'user0001' COLUMN CELL base_info:name timestamp=1534250570112, value=zhangsan1 1 row(s) in 0.1060 seconds 1.8.7-p357 :073 >
獲取user表中row key為user0001,base_info列簇的所有信息
1.8.7-p357 :073 > get 'user_info', 'user0001', 'base_info' COLUMN CELL base_info:name timestamp=1534250570112, value=zhangsan1 1 row(s) in 0.0830 seconds 1.8.7-p357 :074 >
查詢user_info表中的所有信息
1.8.7-p357 :075 > scan 'user_info'

ROW COLUMN+CELL baiyc_20150716_0001 column=base_info:age, timestamp=1534250642273, value=21 baiyc_20150716_0001 column=base_info:name, timestamp=1534250641636, value=baiyc1 baiyc_20150716_0001 column=extra_info:Hobbies, timestamp=1534250642780, value=music baiyc_20150716_0002 column=base_info:age, timestamp=1534250642396, value=22 baiyc_20150716_0002 column=base_info:name, timestamp=1534250641676, value=baiyc2 baiyc_20150716_0002 column=extra_info:Hobbies, timestamp=1534250642826, value=sport baiyc_20150716_0003 column=base_info:age, timestamp=1534250642438, value=23 baiyc_20150716_0003 column=base_info:name, timestamp=1534250641719, value=baiyc3 baiyc_20150716_0003 column=extra_info:Hobbies, timestamp=1534250642869, value=music baiyc_20150716_0004 column=base_info:age, timestamp=1534250642499, value=24 baiyc_20150716_0004 column=base_info:name, timestamp=1534250641787, value=baiyc4 baiyc_20150716_0004 column=extra_info:Hobbies, timestamp=1534250642913, value=sport baiyc_20150716_0005 column=base_info:age, timestamp=1534250642555, value=25 baiyc_20150716_0005 column=base_info:name, timestamp=1534250641855, value=baiyc5 baiyc_20150716_0005 column=extra_info:Hobbies, timestamp=1534250642971, value=music baiyc_20150716_0006 column=base_info:age, timestamp=1534250642607, value=26 baiyc_20150716_0006 column=base_info:name, timestamp=1534250641906, value=baiyc6 baiyc_20150716_0006 column=extra_info:Hobbies, timestamp=1534250643032, value=sport baiyc_20150716_0007 column=base_info:age, timestamp=1534250642655, value=27 baiyc_20150716_0007 column=base_info:name, timestamp=1534250641967, value=baiyc7 baiyc_20150716_0007 column=extra_info:Hobbies, timestamp=1534250643075, value=music baiyc_20150716_0008 column=base_info:age, timestamp=1534250642709, value=28 baiyc_20150716_0008 column=base_info:name, timestamp=1534250642082, value=baiyc8 baiyc_20150716_0008 column=extra_info:Hobbies, timestamp=1534250674681, value=sport user0001 column=base_info:name, timestamp=1534250570112, value=zhangsan1 zhangsan_20150701_0001 column=base_info:age, timestamp=1534250640240, value=21 zhangsan_20150701_0001 column=base_info:name, timestamp=1534250639664, value=zhangsan1 zhangsan_20150701_0001 column=extra_info:Hobbies, timestamp=1534250641009, value=music zhangsan_20150701_0002 column=base_info:age, timestamp=1534250640310, value=22 zhangsan_20150701_0002 column=base_info:name, timestamp=1534250639746, value=zhangsan2 zhangsan_20150701_0002 column=extra_info:Hobbies, timestamp=1534250641078, value=sport zhangsan_20150701_0003 column=base_info:age, timestamp=1534250640367, value=23 zhangsan_20150701_0003 column=base_info:name, timestamp=1534250639808, value=zhangsan3 zhangsan_20150701_0003 column=extra_info:Hobbies, timestamp=1534250641226, value=music zhangsan_20150701_0004 column=base_info:age, timestamp=1534250640439, value=24 zhangsan_20150701_0004 column=base_info:name, timestamp=1534250639866, value=zhangsan4 zhangsan_20150701_0004 column=extra_info:Hobbies, timestamp=1534250641291, value=sport zhangsan_20150701_0005 column=base_info:age, timestamp=1534250640540, value=25 zhangsan_20150701_0005 column=base_info:name, timestamp=1534250639931, value=zhangsan5 zhangsan_20150701_0005 column=extra_info:Hobbies, timestamp=1534250641357, value=music zhangsan_20150701_0006 column=base_info:age, timestamp=1534250640648, value=26 zhangsan_20150701_0006 column=base_info:name, timestamp=1534250640025, value=zhangsan6 zhangsan_20150701_0006 column=extra_info:Hobbies, timestamp=1534250641446, value=sport zhangsan_20150701_0007 column=base_info:age, timestamp=1534250640743, value=27 zhangsan_20150701_0007 column=base_info:name, timestamp=1534250640097, value=zhangsan7 zhangsan_20150701_0007 column=extra_info:Hobbies, timestamp=1534250641547, value=music zhangsan_20150701_0008 column=base_info:age, timestamp=1534250640872, value=28 zhangsan_20150701_0008 column=base_info:name, timestamp=1534250640149, value=zhangsan8 17 row(s) in 0.3440 seconds 1.8.7-p357 :076 >
查詢user_info表中列簇為base_info的信息
1.8.7-p357 :076 > scan 'user_info', {COLUMNS => 'base_info'}
3、刪delete
刪除user_info表row key為user0001,列標示符為base_info:name的數據
1.8.7-p357 :077 > delete 'user_info', 'user0001', 'base_info:name' 0 row(s) in 0.0650 seconds 1.8.7-p357 :078 >
四、HBase常用命令
HBase常用命令status, version, table_help和whoami。本章將介紹了這些命令。
1、status
命令返回包括在系統上運行的服務器的細節和系統的狀態。它的語法如下:如果執行這個命令,它會返回下面的輸出
1.8.7-p357 :078 > status 1 active master, 1 backup masters, 3 servers, 0 dead, 1.6667 average load
2、version
該命令返回HBase系統使用的版本。它的語法如下:如果執行這個命令,它會返回下面的輸出。
1.8.7-p357 :079 > version 1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
3、table_help
此命令將引導如何使用表引用的命令。下面給出的是使用這個命令的語法。當使用此命令時,它顯示幫助主題表相關的命令。
1.8.7-p357 :080 > table_help Help for table-reference commands. You can either create a table via 'create' and then manipulate the table via commands like 'put', 'get', etc. See the standard help information for how to use each of these commands. However, as of 0.96, you can also get a reference to a table, on which you can invoke commands. For instance, you can get create a table and keep around a reference to it via: hbase> t = create 't', 'cf' Or, if you have already created the table, you can get a reference to it: hbase> t = get_table 't' You can do things like call 'put' on the table: hbase> t.put 'r', 'cf:q', 'v' which puts a row 'r' with column family 'cf', qualifier 'q' and value 'v' into table t. To read the data out, you can scan the table: hbase> t.scan which will read all the rows in table 't'. Essentially, any command that takes a table name can also be done via table reference. Other commands include things like: get, delete, deleteall, get_all_columns, get_counter, count, incr. These functions, along with the standard JRuby object methods are also available via tab completion. For more information on how to use each of these commands, you can also just type: hbase> t.help 'scan' which will output more information on how to use that command. You can also do general admin actions directly on a table; things like enable, disable, flush and drop just by typing: hbase> t.enable hbase> t.flush hbase> t.disable hbase> t.drop Note that after dropping a table, your reference to it becomes useless and further usage is undefined (and not recommended).
4、whoami
該命令返回HBase用戶詳細信息。如果執行這個命令,返回當前HBase用戶,如下圖所示
1.8.7-p357 :081 > whoami admin (auth:SIMPLE) groups: admin 1.8.7-p357 :082 >