Get the App
SLTechnology News&Howtos  ›  Database  › 

Use the shell command to manipulate the HBase database

Shulou Source: shulou.com Published: 2022-06-01 09:10:05 09月10日 Update

Operating environment:

Operating system: Ubuntu 16.04.6 LTS

HBase version: HBase 1.1.5

HBase is a highly reliable, high-performance, column-oriented and scalable distributed database, which is mainly used to store unstructured and semi-structured loose data.

Hadoop@dblab:/usr/local/hadoop$ cd / usr/local/hbase

Hadoop@dblab:/usr/local/hbase$ bin/start-hbase.sh # launch HBase

Hadoop@dblab:/usr/local/hbase$ bin/hbase shell # enters Shell mode

# create student table

Hbase (main): 001create 0 > student','Sname','Ssex','Sage','Sdept','course'

0 row (s) in 1.6440 seconds

= > Hbase::Table-student

# View tables that have been created in the database

Hbase (main): 002purl 0 > list

TABLE

Student

1 row (s) in 0.0410 seconds

= > ["student"]

# View table structure

Hbase (main): 003 describe 0 > student'

Table student is ENABLED

Student

COLUMN FAMILIES DESCRIPTION

{NAME = > 'Sage', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = >'

NONE', TTL = > 'FOREVER', COMPRESSION = >' NONE', MIN_VERSIONS = > '0mm, BLOCKCACHE = >' true', BLOCKSIZE = > '65536', REPLICATION_SCOPE = >

'0'}

{NAME = > 'Sdept', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = >

'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 050', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE =

>'0'}

{NAME = > 'Sname', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = >

'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 050', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE =

>'0'}

{NAME = > 'Ssex', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = >'

NONE', TTL = > 'FOREVER', COMPRESSION = >' NONE', MIN_VERSIONS = > '0mm, BLOCKCACHE = >' true', BLOCKSIZE = > '65536', REPLICATION_SCOPE = >

'0'}

{NAME = > 'course', BLOOMFILTER = >' ROW', VERSIONS = >'1', IN_MEMORY = > 'false', KEEP_DELETED_CELLS = >' FALSE', DATA_BLOCK_ENCODING = >

'NONE', TTL = >' FOREVER', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 050', BLOCKCACHE = > 'true', BLOCKSIZE = >' 65536', REPLICATION_SCOPE

= >'0'}

5 row (s) in 0.1650 seconds

# add data to the table

Hbase (main): 004put 0 > student','95001','Sname','LiYing'

Hbase (main): 004put 0 > student','95001','Sname','LiYing'

Hbase (main): 005hbase 0 > put 'student','95001','Ssex','male'

Hbase (main): 006 put 0 > student','95001','Sage','22'

Hbase (main): 007 put 0 > student','95001','Sdept','Cs'

Hbase (main): 008 put 0 > student','95001','Course:math','80'

ERROR: Unknown column family! Valid column names: Sage:*, Sdept:*, Sname:*, Ssex:*, course:*

Hbase (main): 009 put 0 > student','95001','course:math','80'

0 row (s) in 0.0330 seconds

# View a cell data

Hbase (main): 010 get 0 > student','95001'

COLUMN CELL

Sage: timestamp=1558580423554, value=22

Sdept: timestamp=1558580447276, value=Cs

Sname: timestamp=1558580336295, value=LiYing

Ssex: timestamp=1558580402507, value=male

Course:math timestamp=1558580543129, value=80

5 row (s) in 0.0850 seconds

# there is a data center in the query table

Hbase (main): 011 scan 0 > student'

ROW COLUMN+CELL

95001 column=Sage:, timestamp=1558580423554, value=22

95001 column=Sdept:, timestamp=1558580447276, value=Cs

95001 column=Sname:, timestamp=1558580336295, value=LiYing

95001 column=Ssex:, timestamp=1558580402507, value=male

95001 column=course:math, timestamp=1558580543129, value=80

1 row (s) in 0.0740 seconds

# Delete all data in the Ssex column in row 95001

Hbase (main): 014 delete 0 > student','95001','Ssex'

Hbase (main): 015 scan 0 > student'

ROW COLUMN+CELL

95001 column=Sage:, timestamp=1558580423554, value=22

95001 column=Sdept:, timestamp=1558580447276, value=Cs

95001 column=Sname:, timestamp=1558580336295, value=LiYing

95001 column=course:math, timestamp=1558580543129, value=80

# Delete all data with 95001 rows in the table

Hbase (main): 016 deleteall 0 > student','95001'

0 row (s) in 0.0390 seconds

# any data that exists in this table

Hbase (main): 017 scan 0 > student'

ROW COLUMN+CELL

# Delete table

Hbase (main): 006 disable 0 > student'

Hbase (main): 009 drop 0 > student'

# exit database operation

Hbase (main): 018purl 0 > exit

Tags: Data database structure structured loose operating system distributed unit query table schema version environment system high performance storage query command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Linux Microsoft Docker