hbase(三)-基本的hbase shell命令

HBase 爲用戶提供了一個非常方便的使用方式, 我們稱之爲“HBase Shell”。
HBase Shell 提供了大多數的 HBase 命令, 通過 HBase Shell 用戶可以方便地創建、刪除及修改表, 還可以向表中添加數據、列出表中的相關信息等、對region進行相關操作等。

在hbase啓動之後,在命令裏面輸入“hbase shell”可以進入hbase shell的操作界面.

[root@ht05 ~]# hbase shell
Version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017

hbase(main):001:0>

同時可以輸入help命令查看hbase裏面所有的命令

hbase(main):001:0> help
HBase Shell, version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017
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, locate_region, show_filters

  Group name: namespace
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

  Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

  Group name: tools
  Commands: 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_dump

  Group name: replication
  Commands: add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, get_peer_config, list_peer_configs, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFs

  Group name: snapshots
  Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshot

  Group name: configuration
  Commands: update_all_config, update_config

  Group name: quotas
  Commands: list_quotas, set_quota

  Group name: security
  Commands: grant, list_security_capabilities, revoke, user_permission

  Group name: procedures
  Commands: abort_procedure, list_procedures

  Group name: visibility labels
  Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility

這裏只講一些簡單的、和數據增刪改查有關的命令,一些其它的命令後面再說,例如region的維護等命令。

1.create

創建表

創建一個具有兩個列族“grad”和“course”的表“scores”。其中表名、行和列都要用單引號括起來,並以逗號隔開。
hbase(main):012:0> create 'scores', 'name', 'grad', 'course'

2.list 命令

查看當前 HBase 中具有哪些表。

hbase(main):012:0> list

3.describe 命令

查看錶“scores”的構造。

hbase(main):012:0> describe 'scores'

4.put 命令

使用 put 命令向表中插入數據,參數分別爲表名、行名、列名和值,其中列名前需要列族最爲前綴,時間戳由系統自動生成。
格式: put 表名,行名,列名([列族:列名]),值
例子:
a. 加入一行數據,行名稱爲“xiapi”,列族“grad”的列名爲”(空字符串)”,值位 1。

hbase(main):012:0> put 'scores', 'xiapi', 'grad:', '1'
hbase(main):012:0> put 'scores', 'xiapi', 'grad:', '2' --修改操作(update)

b. 給“xiapi”這一行的數據的列族“course”添加一列“

hbase(main):012:0> put 'scores', 'xiapi',  'course:china', '97'
hbase(main):012:0> put 'scores', 'xiapi',  'course:math', '128'
hbase(main):012:0> put 'scores', 'xiapi',  'course:english', '85'

5.get 命令

get是一種特殊的scan,可以理解爲hbase裏面查詢數據的方式只有scan一種

a.查看錶“scores”中的行“xiapi”的相關數據。

hbase(main):012:0> get 'scores', 'xiapi'

b.查看錶“scores”中行“xiapi”列“course :math”的值。

hbase(main):012:0> get 'scores', 'xiapi', 'course :math'

或者

hbase(main):012:0> get 'scores', 'xiapi', {COLUMN=>'course:math'}
hbase(main):012:0> get 'scores', 'xiapi', {COLUMNS=>'course:math'}

備註:COLUMN 和 COLUMNS 是不同的,scan 操作中的 COLUMNS 指定的是表的列族, get操作中的 COLUMN 指定的是特定的列,COLUMNS 的值實質上爲“列族:列修飾符”。COLUMN 和 COLUMNS 必須爲大寫。

6.scan 命令

a. 查看錶“scores”中的所有數據。

hbase(main):012:0> scan 'scores'

注意:
scan 命令可以指定 startrow,stoprow 來 scan 多個 row。
例如:

scan 'user_test',{COLUMNS =>'info:username',LIMIT =>10, STARTROW => 'test', STOPROW=>'test2'}

b.查看錶“scores”中列族“course”的所有數據。

hbase(main):012:0> scan  'scores', {COLUMN => 'grad'}
hbase(main):012:0> scan  'scores', {COLUMN=>'course:math'}
hbase(main):012:0> scan  'scores', {COLUMNS => 'course'}
hbase(main):012:0> scan  'scores', {COLUMNS => 'course'}

7. count 命令

hbase(main):068:0> count 'scores'

8.exists 命令

hbase(main):071:0> exists 'scores'

9.delete 命令

刪除表“scores”中行爲“xiaoxue”, 列族“course”中的“math”。

hbase(main):012:0>  delete 'scores', 'xiapi', 'course:math'

10.truncate 命令

hbase(main):012:0>  truncate 'scores'

11.disbale、drop 命令

通過“disable”和“drop”命令刪除“scores”表。

hbase(main):012:0>  disable 'scores' --enable 'scores' 
hbase(main):012:0>  drop 'scores'

12. status命令

hbase(main):072:0> status

13.version命令

hbase(main):073:0> version
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章