Cloud--hbase Shell

Source: Internet
Author: User

The specific HBase shell commands are shown in table 1.1-1 below:

Below we will use the example of "A Student score table" to detail the commonly used HBase commands and how they are used.


Here grad for the table is a column, course for the table is a column family, this column family consists of three columns China, math and Chinese, of course, we can according to our needs in the course to build more column family, such as Computer,physics Add the course column family to the corresponding column. (Note: The columns under the column family can also have no names.) )
1). Create command
Create a table "scores" with two column families "Grad" and "course". The table names, rows, and columns are enclosed in single quotation marks and separated by commas.
HBase (main):012:0> create ' scores ', ' name ', ' Grad ', ' course '

2). List command
View which tables are in the current HBase.
HBase (main):012:0> list

3). Describe command
View the construction of the table "scores".
HBase (main):012:0> describe ' scores '

4). Put command
Use the put command to insert data into the table, with parameters such as table name, row name, column name, and value, where the column family is the most prefixed to the column name and the timestamp is automatically generated by the system.
Format: Put table name, row name, column name ([Column family: Column name]), value
Example:
A. Add one row of data, row name "Xiapi", column Family "grad" column named "(Empty string)", value bit 1.
HBase (main):012:0> put ' scores ', ' Xiapi ', ' Grad: ', ' 1 '
HBase (main):012:0> put ' scores ', ' Xiapi ', ' Grad: ', ' 2 '--Modify operation (update)
B. Add a column "<china,97>" to the column family "course" for the data in the row "Xiapi".
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 command
A. View the data about the row "Xiapi" in Table "scores".
HBase (main):012:0> get ' scores ', ' Xiapi '
B. View the value of the row "Xiapi" column "Course:math" in Table "scores".
HBase (main):012:0> get ' scores ', ' Xiapi ', ' Course:math '
Or
HBase (main):012:0> get ' scores ', ' Xiapi ', {column=> ' Course:math '}
HBase (main):012:0> get ' scores ', ' Xiapi ', {columns=> ' Course:math '}
Note: column and COLUMNS are different, COLUMNS in the scan operation specifies the column family of the table, and the column in the get operation specifies the specific columns, and the value of COLUMNS is essentially the column family: column modifier.COLUMN and COLUMNS must be uppercase.

6). Scan command
A. View all data in the table "scores".
HBase (main):012:0> scan ' scores '
Attention:
The scan command can specify startrow,stoprow to scan multiple row.
For example:
Scan ' User_test ', {COLUMNS = ' info:username ', LIMIT =>10, startrow = ' test ', stoprow=> ' test2 '}
B. View all data for column family "course" in table "scores".
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 command
HBase (Main):068:0> count ' scores '

8). Exists command
HBase (main):071:0> exists ' scores '

9). INCR command (assigned value)

). Delete command
Delete the behavior "Xiaoxue" in the table "scores", and "math" in the column Family "course".
HBase (main):012:0> delete ' scores ', ' Xiapi ', ' Course:math '

ONE). Truncate command
HBase (Main):012:0> truncate ' scores '

). Disbale, Drop command
Delete the "scores" table with the "Disable" and "drop" commands.
HBase (Main):012:0> disable ' scores '--enable ' scores '
HBase (Main):012:0> drop ' scores '

). Status command
HBase (main):072:0> status

). Version command
HBase (main):073:0> version

In addition, in the shell, constants do not need to be quoted, but binary values require double quotation marks, while others are enclosed in single quotation marks. The constants of the HBase shell can be entered by "object.constants" in the shell.

Let's take a look at some of the basic operations commands of the HBase shell, and I've listed several common hbase shell commands, as follows:

Name

Command-expression

Create a table

Create ' table name ', ' column name 1 ', ' Column Name 2 ', ' Column name n '

Add a record

Put ' table name ', ' Row name ', ' Column name: ', ' value '

View Records

Get ' table name ', ' Row name '

View the total number of records in a table

Count ' table name '

Deleting records

Delete ' table name ', ' Row name ', ' column name '

Delete a table

To block the table before it can be deleted, the first step disable ' table name ' Second step drop ' table name '

View all records

Scan "Table name"

View all data in a column of a table

Scan "table name", [' Column name: ']

Update record

is to rewrite it again to overwrite

1. Create a table

HBase (Main): 011:0>create ' member ', ' member_id ', ' address ', ' info '

2. Get a description of the table

HBase (main): 012:0>list

3. Delete a column family, alter,disable,enable

We built 3 column families before, but found that the member_id is redundant because he is the primary key, so we're going to delete it.

HBase (Main): 003:0>alter ' member ',{name=> ' member_id ',method=> ' delete '}

Error:table Memberis enabled. Disable it first before altering.

Error, delete the column family must first give the table to disable off.

HBase (Main): 004:0>disable ' member '

The column family has been deleted and we continue to enable the table

HBase (main):008:0> enable ' member '

4. List all the tables

HBase (main): 028:0>list

5.drop a table

HBase (Main): 029:0>disable ' temp_table '

6. Whether the query table exists

HBase (Main): 021:0>exists ' member '

7. Determine if the table is enable

HBase (Main): 034:0>is_enabled ' member '

8. Determine if the table is disable

HBase (Main): 032:0>is_disabled ' member '

1. Insert several records

Put ' member ', ' Scutshuxue ', ' info:age ', ' 24 '

Put ' member ', ' Scutshuxue ', ' info:birthday ', ' 1987-06-17 '

Put ' member ', ' Scutshuxue ', ' info:company ', ' Alibaba '

Put ' member ', ' Scutshuxue ', ' address:contry ', ' China '

Put ' member ', ' Scutshuxue ', ' address:province ', ' Zhejiang '

Put ' member ', ' Scutshuxue ', ' address:city ', ' Hangzhou '

2. Get a piece of data

Get all the data for an ID

HBase (Main): 001:0>get ' member ', ' Scutshuxue '

Get an ID, all data for a column family

HBase (Main): 002:0>get ' member ', ' Scutshuxue ', ' info '

Gets an ID that all data for a column in a column family

HBase (Main): 002:0>get ' member ', ' Scutshuxue ', ' info:age '

6. Update a record

Change the age of Scutshuxue to 99

HBase (Main): 004:0>put ' member ', ' Scutshuxue ', ' info:age ', ' 99 '

4. Full table Scan:

HBase (Main): 013:0>scan ' member '

5. Remove the ' info:age ' field for the value with ID temp

HBase (Main): 016:0>delete ' member ', ' temp ', ' info:age '

6. Delete entire rows

HBase (Main): 001:0>deleteall ' member ', ' Xiaofeng '

7. How many rows are in the query table:

HBase (Main): 019:0>count ' member '

8. Add ' info:age ' field to ' Xiaofeng ' ID and increment with counter

HBase (Main): 057:0*incr ' member ', ' Xiaofeng ', ' info:age '

HBase (Main): 058:0>get ' member ', ' Xiaofeng ', ' info:age '

HBase (Main): 059:0>incr ' member ', ' Xiaofeng ', ' info:age '

HBase (Main): 060:0>get ' member ', ' Xiaofeng ', ' info:age '

Gets the value of the current count

HBase (Main): 069:0>get_counter ' member ', ' Xiaofeng ', ' info:age '

9. Empty the entire table:

HBase (Main): 035:0>truncate ' member '

Truncating ' member ' table (it may take a while):

-Disabling Table ...

-Dropping table ...

-Creating Table ...

0 row (s) in 4.3430seconds

It can be seen that HBase is the first to drop the disable off, and then drop the rebuild table to achieve truncate function.

Reprinted from Http://www.cnblogs.com/linjiqin/archive/2013/03/08/2949339.html and http://blog.csdn.net/scutshuxue/article/details/6988348

Cloud--hbase Shell

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.