Hadoop Learning Notes (15)---the use of Hbase shell commands

Source: Internet
Author: User
Tags versions

1. Start HBase, go to the Bin folder under the HBase folder, and then execute the command:

HBase Shell
[Root@hadoop0 bin]# hbase shell
hbase shell; Enter ' help<return> ' for list of supported commands.
Type "exit<return>" to leave the HBase Shell
Version 0.98.12.1-hadoop1, rb00ec5da604d64a0bdc7d92452b1e0559f0f5d73, Sun may 12:22:29 PDT 2015

2. To create a table:

Create ' users ', ' user_id ', ' address ', ' info '

Table users, three clusters: user_id, address, info

3. View All tables: List

HBase (main):003:0> list
TABLE                                                                                                                                                                       
users                                                                                                                                                                       
1 row (s) in 0.0400 seconds

4. View table structure: Describe ' users '

HBase (main):004:0> describe ' users ' Table users is ENABLED                                                                                                                                                     Users                                                                                                                                                 
COLUMN Families DESCRIPTION {NAME = ' address ', data_block_encoding = ' NO ' NE ', Bloomfilter = ' ROW ', Replication_scope = ' 0 ', VERSIONS = ' 1 ', COMPRESSION = ' NONE ', min_versions =&gt ; ' 0 ', TTL = ' FORE VER ', keep_deleted_cells = ' false ', BLOCKSIZE = ' 65536 ', in_memory = ' false ', Blockcache = = ' true '} {NAME = ' info ', Data_block_encodin G = ' 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 = ' tr UE '} {NAME = ' user_id ', data_block_encoding = > ' None ', Bloomfilter = ' ROW ', Replication_scope = ' 0 ', VERSIONS = ' 1 ', COMPRESSION = ' None ', Min_versi ONS = ' 0 ', TTL = ' FORE VER ', keep_deleted_cells = ' false ', BLOCKSIZE = ' 65536 ', in_memory = ' false ', B Lockcache = ' true '} 3 row (s) in 0.1000 seconds

5. Delete the table:

The table cannot be deleted directly, and the disable operation is required first:

If you delete directly, the following error is reported:

HBase (Main):007:0> drop ' user_tmp '

error:table user_tmp is enabled. Disable it first.

Here's some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop ' t1 '
  hbase> drop ' ns1:t1 '

Should first 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. See if the table exists:

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

7. Check to see if you are prohibited:

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. Insert Data:

HBase (main):001:0> put ' users ', ' xiaoming ', ' info:company ', ' Baidu '

8. View the data in the table:

Scan ' users '

9. Get Xiaoming's information:

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

View Age Only:

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. Update the RECORD:

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

Now check age is the newest age:

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

How to view the history of the record. :

View Previous data:

HBase (main):011:0> get ' users ', ' xiaoming ',{column=> ' info:age ', versions=>2}

Show Timestamp data:

HBase (main):016:1> get ' users ', ' xiaoming ',{column=> ' info:age ', timestamp=>1433713054227}

Delete data:

Delete ' users ', ' xiaoming ', ' info:age '
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.