Basic commands of Hbase Shell

Article directory 1, Enter HBase command line 2, Operation of HBase table 3, create 4, View table list 5, View table de...
1, Enter HBase command line
2, Operation of HBase table
3, create
4, View table list
5, View table details desc
6, Modify the definition of table alter
7, Operation of data in HBase table
Eight. Increase put
9, get + scan
10, delete

Article directory

1, Enter HBase command line

On the random server node you installed, execute the command: hbase shell, which will enter your hbase shell client

[root@zj1 conf]# hbase shell 2019-12-19 12:55:49,053 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available 2019-12-19 12:55:52,523 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/soft/hbase120/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/soft/hadoop260/share/hadoop/common/lib/slf4j-log4j12-1.7.5.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.0-cdh5.14.2, rUnknown, Tue Mar 27 13:31:54 PDT 2018

Note, first look at the tips. Is there a very important sentence

HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell

Help get help

help: get all command prompts

help 'dml': get tips for a set of commands

Help "put": get prompt help for a single command

Exit to exit hbase shell client

2, Operation of HBase table

Operations on tables include (create, view the list of tables. View the table details desc, delete the table drop, clear the table truncate, and modify the table definition alter)

3, create

hbase(main):004:0> 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'}} hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 1000000, MOB_COMPACT_PARTITION_POLICY => 'weekly'} 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.

You can see one of the tips

hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}

Where t1 is the table name, F1, F2 and F3 are the column cluster names, such as:

hbase(main):005:0> create 'myHbase',{NAME => 'myCard',VERSIONS => 5 } 0 row(s) in 1.7150 seconds => Hbase::Table - myHbase

A table named myHbase is created. There is a column cluster named myCard in the table, with 5 version information reserved

4, View table list

You can enter the following commands to view help commands

hbase(main):006: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):007:0>

Enter list directly to view

hbase(main):007:0> list TABLE customer myHbase mydemo:users 3 row(s) in 0.0270 seconds => ["customer", "myHbase", "mydemo:users"]

The newly created table myHbase is in it

5, View table details desc

A brace is equivalent to a column cluster.

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', DATA_BLO CK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.1210 seconds

6, Modify the definition of table alter

1. Add a column cluster

hbase(main):010:0> alter 'myHbase', NAME=>'myinfo' Updating all regions with the new schema... 1/1 regions updated. Done. 0 row(s) in 2.1320 seconds hbase(main):011:0> desc 'myHbase' Table myHbase is ENABLED myHbase COLUMN FAMILIES DESCRIPTION {NAME => 'myCard', BLOOMFILTER => 'ROW', VERSIONS => '5', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLO CK_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', DATA_BLO CK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'} 2 row(s) in 0.0630 seconds

2. Delete a column cluster

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>

To delete a column cluster, you can also execute the following command

alter 'myHbase', 'delete' => 'myCard'

3. Add column cluster hehe and delete column cluster myInfo

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

4. Clear table truncate

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

5. drop table

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'

If you delete a table directly, an error will be reported. Disable the table first as prompted

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>

7, Operation of data in HBase table

About data operation (add put, delete delete, check get + scan, change = = add in disguise)

Create user table, including info and data column clusters

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>

Eight. Increase put

To view help, you need to pass in table name, rowkey, column cluster name, value, etc

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, }
hbase(main):020:0>

Insert information into the user table, row key is user0001, column cluster base info adds name column indicator, value is zhangsan1

hbase(main):020:0> put 'user_info', 'user0001', 'base_info:name', 'zhangsan1' 0 row(s) in 0.2900 seconds hbase(main):021:0>

You can add more data here

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'

9, get + scan

Get all the information in the user table with row key as user0001

hbase(main):068:0> get 'user_info','user0001' COLUMN CELL base_info:name timestamp=1576784157404, value=zhangsan1 1 row(s) in 0.0290 seconds hbase(main):069:0>

Get all the information of the info column cluster in the user table with row key as Zhangsan

hbase(main):074:0> get 'user_info' ,'zhangsan_20150701_0001','base_info' COLUMN CELL base_info:age timestamp=1576784099917, value=21 base_info:name timestamp=1576784078881, value=zhangsan1 2 row(s) in 0.0080 seconds

Query all information in the user? Info table

hbase(main):026:0> scan 'user_info'

Query the information in the user info table whose column cluster is base info

hbase(main):075:0> scan 'user_info',{COLUMNS=>'base_info'}

10, delete

Delete the data whose row key is rk0001 and column indicator is base Info: name in user info table

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>
beautiful_huang Published 85 original articles, won praise 103, visited 3949 Private letter follow

5 February 2020, 05:22 | Views: 1513

Add new comment

For adding a comment, please log in
or create account

0 comments