Hadoop學習筆記(十五)---Hbase shell命令的使用

來源:互聯網
上載者:User

1.啟動hbase, 進入hbase檔案夾下面的bin檔案夾,然後執行命令:

hbase shell
[root@hadoop0 bin]# hbase shellHBase Shell; enter 'help<RETURN>' for list of supported commands.Type "exit<RETURN>" to leave the HBase ShellVersion 0.98.12.1-hadoop1, rb00ec5da604d64a0bdc7d92452b1e0559f0f5d73, Sun May 17 12:22:29 PDT 2015hbase(main):001:0> 

2。建立表:

create 'users','user_id', 'address', 'info'

表users,三個列簇:user_id, address, info

3.查看所有表:list

hbase(main):003:0> listTABLE                                                                                                                                                                       users                                                                                                                                                                       1 row(s) in 0.0400 seconds

4.查看錶結構:describe 'users'

hbase(main):004:0> describe 'users'Table users is ENABLED                                                                                                                                                      users                                                                                                                                                                       COLUMN FAMILIES DESCRIPTION                                                                                                                                                 {NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                      {NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                         {NAME => 'user_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                      3 row(s) in 0.1000 seconds

5.刪除表:

表不能直接刪除,需要先進行disable操作:

如果直接刪除會報下面的錯誤:

hbase(main):007:0> drop 'user_tmp'ERROR: Table user_tmp 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'

應該先disable:

hbase(main):008:0> disable 'user_tmp'0 row(s) in 1.4120 seconds
hbase(main):010:0> drop 'user_tmp'0 row(s) in 0.2320 seconds

6.查看錶是否存在:

hbase(main):013:0> exists 'users'Table users does exist                                                                                                                                                      0 row(s) in 0.0330 seconds

7.查看是否禁止:

hbase(main):016:0> is_enabled 'users'true                                                                                                                                                                        0 row(s) in 0.0410 seconds
hbase(main):002:0> is_disabled 'users'false                                                                                                                                                                       0 row(s) in 0.0270 seconds

7.插入資料:

hbase(main):001:0> put 'users', 'xiaoming','info:company','baidu'

8.查看錶中的資料:

scan 'users'

9.獲得小明的資訊:

hbase(main):003:0> get 'users','xiaoming'COLUMN                                       CELL                                                                                                                            info:age                                    timestamp=1433712506712, value=22                                                                                               info:company                                timestamp=1433712630400, value=baidu                                                                                           2 row(s) in 0.0560 seconds

只查看年齡:

hbase(main):004:0> get 'users','xiaoming','info:age'COLUMN                                       CELL                                                                                                                            info:age                                    timestamp=1433712506712, value=22                                                                                              1 row(s) in 0.0280 seconds

10.更新記錄:

hbase(main):007:0> put 'users','xiaoming','info:age','24'0 row(s) in 0.0140 seconds

現在查看年齡就是最新的年齡:

hbase(main):009:0> get 'users','xiaoming','info:age'COLUMN                                       CELL                                                                                                                            info:age                                    timestamp=1433713054227, value=24                                                                                              1 row(s) in 0.0140 seconds

怎麼查看記錄呢。:

查看上一個資料:

hbase(main):011:0> get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>2}

顯示時間戳記資料:

hbase(main):016:1> get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1433713054227}

刪除資料:

delete 'users','xiaoming','info:age'
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.