HBase2. 4.8 detailed tutorial (II) HBase shell command

Miss Zhu 2022-02-13 08:38:32 阅读数:812

hbase2. hbase detailed tutorial ii

         adopt hbase shell command , Have access to HBase Command line interface .

hbase shell

         As shown in the figure below :
 Insert picture description here

         see HBase Version number :

version

 Insert picture description here

         see HBase Status of each cluster :

status

 Insert picture description here

         Be careful , If you execute HBase Shell When ordered , There is :
Server is not running yet abnormal , It should be closed Hadoop Security mode of

hadoop dfsadmin -safemode leave

         And restart Hadoop、ZooKeeper、HBase colony .
         attach Hadoop Safe mode other common commands :

# Enter safe mode 
hadoop dfsadmin -safemode enter
# View current mode 
hadoop dfsadmin -safemode get

Table structure operations

        HBase Shell In the syntax , All string parameters must be enclosed in single quotes , And case sensitive .
Build table
establish Student surface , There are two column families in the table : Stulnfo and Grades

create 'Student','StuInfo','Grades'

 Insert picture description here

list Command to view all tables :
 Insert picture description here

exists ‘ Table name ’ Check to see if there is this table
 Insert picture description here

describe ‘ Table name ’, You can view all column families in the table
 Insert picture description here

Modify table
to Student Add a new table hobby Column family of

alter 'Student','hobby'

Delete hobby Column family
alter ‘Student’,‘delete’=>‘hobby’

Delete table
Want to delete table , You have to disable the table first , Then delete

disable 'Student'
drop 'Student'

Data manipulation

Here is an example
 Insert picture description here

The new data
Note that a new addition is a new addition to a cell

put 'Student', '0001', 'StuInfo:Name', 'Tom Green', 1

The first parameter Student Is the name of the watch ;
The second parameter 0001 Is the name of the row key , Is a string type ;
The third parameter StuInfo:Name Name the column family and column , The middle is separated by a colon . The family name must be created , otherwise HBase Will report a mistake ; Column names are temporarily defined , Therefore, the columns in the column family can be expanded at will ;
Fourth parameter Tom Green Is the value of the cell . stay HBase in , All data is in the form of a string ;
Last parameter 1 For timestamps , If you do not set the timestamp , Then the system will automatically insert the current time as the timestamp .

Want to add data, such as in the icon , You need to continue to execute the following statement

put 'Student', '0001', 'StuInfo:Name', 'Tom Green', 1
put 'Student', '0001', 'StuInfo:Age', '18'
put 'Student', '0001', 'StuInfo:Sex', 'Male'
put 'Student', '0001', 'StuInfo:BigData', '80'
put 'Student', '0001', 'Grades:Computer', '90'
put 'Student', '0001', 'Grades:Math', '85'

Modifying data
If put The cell in the statement already exists , Instant key 、 Column families and column names already exist , Without considering the timestamp , perform put sentence , Then you can update the data .

put 'Student', '0001', 'StuInfo:Name', 'Jim Green'

If the timestamp is set to n, You can save n Data .

Delete data
It is divided into deleting cell data and row data
Delete cell data :

Delete Student The row key in the table is 0001,Grades Column family members are Math, Timestamp is less than or equal to 2 The data of :`

delete 'Student', '0001', 'Grades:Math', 2`

Delete 0002 Row data :

delete 'Student', '0002', 'Grades'

Query data
according to rowid Query row data

get 'student', '0001'

Query full table data :

scan 'Student'
copyright:author[Miss Zhu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130838300857.html