AI智能
改变未来

HBase shell常用命令工具—-指南

#########一定要注意大小写,以前那篇是用word编辑拷贝的,所以好多错误,现在重新搞了一版,亲测。。。。。可以当工具使用 

################################################

                                    注意大小写

################################################

目录

1、打开hbase shell,使用help命令查看使用规则

2、查看具体命令的使用

3、查看服务器的状态

4、查看table列表

5、创建表空间

6、创建表

7、查看表的基本信息

8、启用/禁用表

9、查看表是否存在

10、查看表是否启用/禁用

11、删除表

12、添加列族

13、删除列族

14、修改列族存储版本

15、插入数据

16、获取指定行信息、列族信息、列信息

17、删除列、行数据

18、scan查询数据

19、数据过滤

20、多条件筛选

21、根据rowkey筛选数据

1、打开hbase shell,使用help命令查看使用规则

[code][root@t1-25-19 ~]# hbase shellHBase Shell; enter \'help<RETURN>\' for list of supported commands.Type \"exit<RETURN>\" to leave the HBase ShellVersion 1.1.2.2.6.0.3-8, r3307790b5a22cf93100cad0951760718dee5dec7, Sat Apr  1 21:41:47 UTC 2017hbase(main):001:0> helpHBase Shell, version 1.1.2.2.6.0.3-8, r3307790b5a22cf93100cad0951760718dee5dec7, Sat Apr  1 21:41:47 UTC 2017Type \'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: generalCommands: status, table_help, version, whoamiGroup name: ddlCommands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filtersGroup name: namespaceCommands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tablesGroup name: dmlCommands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserveGroup name: toolsCommands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, splitormerge_enabled, splitormerge_switch, trace, unassign, wal_roll, zk_dumpGroup name: replicationCommands: add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFsGroup name: snapshotsCommands: clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot, snapshot_all, snapshot_restoreGroup name: configurationCommands: update_all_config, update_configGroup name: quotasCommands: list_quota_snapshots, list_quota_table_sizes, list_quota_violations, list_quotas, set_quotaGroup name: securityCommands: grant, revoke, user_permissionGroup name: proceduresCommands: abort_procedure, list_proceduresGroup name: visibility labelsCommands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibilityGroup name: rsgroupCommands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_rsgroup_servers, move_rsgroup_tables, remove_rsgroupSHELL USAGE:Quote all names in HBase Shell such as table and column names.  Commas delimitcommand parameters.  Type <RETURN> after entering a command to run it.Dictionaries of configuration used in the creation and alteration of tables areRuby 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 asNAME, 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, usedouble-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/book.html

2、查看具体命令的使用

[code]hbase(main):002:0> help \'put\'Put a cell \'value\' at specified table/row/column and optionallytimestamp 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\', ts1hbase> 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 referencet to table \'t1\', the corresponding command would be:hbase> t.put \'r1\', \'c1\', \'value\', ts1, {ATTRIBUTES=>{\'mykey\'=>\'myvalue\'}}

3、查看服务器的状态

[code]hbase(main):003:0> status1 active master, 0 backup masters, 3 servers, 0 dead, 159.6667 average load

4、查看table列表

[code]hbase(main):004:0> listTABLEcrs_dev_ns:crs_date

5、创建表空间

[code]hbase(main):007:0> create_namespace \'demo\'0 row(s) in 0.0830 seconds

6、创建表

命令格式:create ‘表名称’,’列族名称1’,‘列族名称2’,‘列族名称N’

[code]hbase(main):009:0> create \'demo:demo\',\'info\'0 row(s) in 2.2980 seconds=> Hbase::Table - demo:demo

7、查看表的基本信息

命令格式:desc ‘表名’

describe \’表名\’

[code]hbase(main):009:0> create \'demo:demo\',\'info\'0 row(s) in 2.2980 seconds=> Hbase::Table - demo:demohbase(main):010:0> desc \'demo:demo\'Table demo:demo is ENABLEDdemo:demoCOLUMN FAMILIES DESCRIPTION{NAME => \'info\', BLOOMFILTER => \'ROW\', VERSIONS => \'1\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION => \'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}  

8、启用/禁用表

[code]hbase(main):012:0> disable \'demo:demo\'0 row(s) in 2.2750 secondshbase(main):013:0> enable \'demo:demo\'0 row(s) in 1.2760 seconds

9、查看表是否存在

[code]hbase(main):022:0> exists \'demo:demo\'Table demo:demo does exist0 row(s) in 0.0300 seconds

10、查看表是否启用/禁用

[code]hbase(main):024:0> is_disabled \'demo:demo\'true0 row(s) in 0.0220 secondshbase(main):025:0> is_enabled \'demo:demo\'false0 row(s) in 0.0120 seconds

11、删除表

[code]hbase(main):023:0> disable \'demo:demo\'0 row(s) in 2.2410 secondshbase(main):026:0> drop \'demo:demo\'0 row(s) in 1.3580 seconds

12、添加列族

命令格式:alter ‘表名’,‘列族名’

[code]hbase(main):028:0> alter \'demo:demo\',\'timeInfo\'Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 1.9250 secondshbase(main):029:0> desc \'demo:demo\'Table demo:demo is ENABLEDdemo:demoCOLUMN FAMILIES DESCRIPTION{NAME => \'info\', BLOOMFILTER => \'ROW\', VERSIONS => \'1\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION => \'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}{NAME => \'timeInfo\', BLOOMFILTER => \'ROW\', VERSIONS => \'1\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION =>\'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}2 row(s) in 0.0270 seconds

13、删除列族

[code]hbase(main):030:0> alter \'demo:demo\',{NAME=>\'timeInfo\',METHOD=>\'delete\'}Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 1.9430 secondshbase(main):031:0> desc \'demo:demo\'Table demo:demo is ENABLEDdemo:demoCOLUMN FAMILIES DESCRIPTION{NAME => \'info\', BLOOMFILTER => \'ROW\', VERSIONS => \'1\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION => \'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}1 row(s) in 0.0100 seconds

14、修改列族存储版本

默认情况下,列族只存储一个版本的数据,如果需要存储多个版本的数据,则需要修改列族的树形。修改后可通过desc命令查看。

[code]hbase(main):007:0> alter \'demo:demo\',NAME=>\'timeInfo\',VERSIONS=>\'2\'Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 1.9250 secondshbase(main):008:0> desc \'demo:demo\'Table demo:demo is ENABLEDdemo:demoCOLUMN FAMILIES DESCRIPTION{NAME => \'info\', BLOOMFILTER => \'ROW\', VERSIONS => \'1\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION => \'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}{NAME => \'timeInfo\', BLOOMFILTER => \'ROW\', VERSIONS => \'2\', IN_MEMORY => \'false\', KEEP_DELETED_CELLS => \'FALSE\', DATA_BLOCK_ENCODING => \'NONE\', TTL => \'FOREVER\', COMPRESSION =>\'NONE\', MIN_VERSIONS => \'0\', BLOCKCACHE => \'true\', BLOCKSIZE => \'65536\', REPLICATION_SCOPE => \'0\'}2 row(s) in 0.0290 seconds

15、插入数据

命令格式:put ‘表名’,‘行键’,‘列族:列’,‘值’

注意:如果新增数据的行键值、列族名、列名与原有数据完全相同,则相当于更新操作

[code]hbase(main):010:0> put \'demo:demo\',\'123\',\'info:name\',\'tom\'0 row(s) in 0.1360 secondshbase(main):011:0> put \'demo:demo\',\'123\',\'info:age\',120 row(s) in 0.0270 secondshbase(main):012:0> scan \'demo:demo\'ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857153341, value=12123                                          column=info:name, timestamp=1591857128725, value=tom1 row(s) in 0.0270 seconds

16、获取指定行信息、列族信息、列信息

[code]hbase(main):013:0> get \'demo:demo\',\'123\'COLUMN                                        CELLinfo:age                                     timestamp=1591857153341, value=12info:name                                    timestamp=1591857128725, value=tom2 row(s) in 0.0290 secondshbase(main):015:0> get \'demo:demo\',\'123\',\'timeInfo\'COLUMN                                        CELL0 row(s) in 0.0020 secondshbase(main):016:0> get \'demo:demo\',\'123\',\'info:name\'COLUMN                                        CELLinfo:name                                    timestamp=1591857128725, value=tom1 row(s) in 0.0050 seconds

17、删除列、行数据

[code]hbase(main):018:0> delete \'demo:demo\',\'123\',\'info:name\'0 row(s) in 0.0080 secondshbase(main):019:0> scan \'demo:demo\'ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857153341, value=121 row(s) in 0.0270 secondshbase(main):027:0> deleteall \'demo:demo\',\'123\'0 row(s) in 0.0050 secondshbase(main):028:0> scan \'demo:demo\'ROW                                           COLUMN+CELL0 row(s) in 0.0120 seconds

18、scan查询数据

[code]hbase(main):032:0> scan \'demo:demo\',{COLUMNS=>\'info\'}ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=12123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0200 secondshbase(main):033:0> scan \'demo:demo\',{COLUMNS=>\'info:age\'}ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=121 row(s) in 0.0130 secondshbase(main):034:0> scan \'demo:demo\',{COLUMNS=>[\'info:age\',\'info:name\'],LIMIT=>2}ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=12123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0120 secondshbase(main):036:0> scan \'demo:demo\',{COLUMNS=>[\'info:age\',\'info:name\'],LIMIT=>2,STARTROW=>\'000\',STOPROW=>\'234\'}ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=12123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0090 seconds

19、数据过滤

[code]hbase(main):039:0> scan \'demo:demo\',filter=>\"ValueFilter(=,\'age:12\')\"NameError: undefined local variable or method `filter\' for #<Object:0x5ea7bc4>hbase(main):040:0> scan \'demo:demo\',FILTER=>\"ValueFilter(=,\'binary:12\')\"ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=121 row(s) in 0.0670 secondshbase(main):041:0> scan \'demo:demo\',FILTER=>\"ValueFilter(=,\'substring:t\')\"ROW                                           COLUMN+CELL123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0200 secondshbase(main):042:0> scan \'demo:demo\',FILTER=>\"ColumnPrefixFilter(\'n\')\"ROW                                           COLUMN+CELL123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0470 seconds

20、多条件筛选

[code]hbase(main):049:0> scan \'demo:demo\',{FILTER=>\"ColumnPrefixFilter(\'n\') AND ValueFilter(=,\'substring:t\')\"}ROW                                           COLUMN+CELL123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.0470 seconds

21、根据rowkey筛选数据

[code]hbase(main):006:0> scan \'demo:demo\',FILTER=>\"PrefixFilter(\'123\')\"ROW                                           COLUMN+CELL123                                          column=info:age, timestamp=1591857852613, value=12123                                          column=info:name, timestamp=1591857842427, value=tom1 row(s) in 0.3010 seconds

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » HBase shell常用命令工具—-指南