HBase provides users with a very convenient way to use it, which we call "HBase Shell."
The HBase shell provides most hbase commands, which can be easily created, deleted, and modified by HBase shell users, as well as adding data to tables, listing related information in tables, and so on.
Note: When you write the HBase shell command incorrectly, delete it with "delete" on the keyboard, "Backspace" does not work.
After HBase is started, the user can enter the HBase Shell with the following command, as follows:
hadoop@ubuntu:~$ hbase Shell
hbase shell; Enter ' help<return> ' for list of supported commands.
Type "exit<return>" to leave the HBase Shell
Version 0.94.3, r1408904, Wed Nov 19:55:11 UTC 2012
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.