HBase learning Summary (2): HBase introduction and basic operations

Source: Internet
Author: User
Tags ocaml

HBase learning Summary (2): HBase introduction and basic operations

(HBase is a type of Database: Hadoop database, which is a NoSQL storage system designed to quickly read and write large-scale data at random. This document describes the basic operations of HBase on the premise that HBase is successfully installed and started properly .)
1. HBase Introduction
What is HBase (Hadoop Database? There are two common sayings:
First, it is a sparse, distributed, persistent, and multidimensional ordered ing. It is based on row key, column key, and timestamp) create an index.
Second, it is a type of key value storage. It is a column family-oriented database, and sometimes a database that stores multi-timestamp version ing.
Both of the preceding descriptions are correct. However, HBase is a highly reliable, high-performance, column-oriented, and Scalable Distributed Storage System. It is a platform for storing and retrieving data with random access. You can write data as needed and then read the data as needed.

HBase has the following features:
First, it does not mind data types, allows dynamic and flexible data models, and does not limit the types of stored data. Therefore, it can freely store structured and semi-structured data.
Second, it does not use the SQL language or emphasize the relationship between data.
Third, it does not allow cross-row transactions. You can store an integer in one column of a row, and store a string in the same column of another row.
Fourth, it is designed to run on a server cluster, rather than a single server. This means a powerful and scalable way to use data.
From the features of HBase, we can see that the design and objectives of HBase are different from those of traditional relational databases.

Ii. Basic HBase operations
If you have successfully installed HBase and started HBase normally, you can use HBase Shell to interact with HBase through command lines.
1. Start HBase Shell
Go to the "bin" directory of the HBase decompression package and run the "./hbase shell" or "sh hbase shell" command to start HBase Shell. The information after startup is as follows:

HBase Shell; enter 'help
  
   ' for list of supported commands.Type "exit
   
    " to leave the HBase ShellVersion 1.0.1, r66a93c09df3b12ff7b86c39bc8475c60e15af82d, Fri Apr 17 22:14:06 PDT 2015hbase(main):001:0>
   
  

To verify whether HBase is successfully installed, enter "list" to view all the tables in HBase. The command execution is as follows:

hbase(main):001:0> listTABLE 0 row(s) in 0.2390 seconds=> []

HBase contains 0 tables because it is the first logon.

2. Create a table
HBase uses a table as the top-level structure to store data and writes data to HBase, that is, writing data to the table. Create a table "mytable" with a column family ("cf") as follows ":

hbase(main):002:0> create 'mytable', 'cf'0 row(s) in 0.3250 seconds=> Hbase::Table - mytablehbase(main):003:0> listTABLE mytable 1 row(s) in 0.0090 seconds=> ["mytable"]

Using the "list" command, we can see that the table is successfully created.

3. Write Data
After the table is created, some data needs to be written. For example, if we want to write "hello hbase" to the table, we will write "cf: "hello hbase" is inserted into the data unit corresponding to the info column ". Run the following command:

hbase(main):004:0> put 'mytable', 'first', 'cf:info', 'hello hbase'0 row(s) in 0.0970 seconds

We can add more values as follows:

hbase(main):005:0> put 'mytable', 'second', 'cf:name', 'zhou'0 row(s) in 0.0180 secondshbase(main):006:0> put 'mytable', 'third', 'cf:nation', 'China'0 row(s) in 0.0080 seconds

The table contains three rows and three data units. When using columns, you have not defined these columns in advance, nor have you defined the data types stored in each column. Therefore, HBase is a schema-free database.

4. Read data
HBase can read data in two ways: get and scan. Get can read the data information of a row, and scan can read the data information of all rows in the table.
Run the get command as follows:

hbase(main):008:0> get 'mytable', 'first'COLUMN CELL cf:info timestamp=1435548279711, value=hello hbase 1 row(s) in 0.0770 seconds

This command outputs all data units of the row.

Run the scan command as follows:

hbase(main):009:0> scan 'mytable'ROW COLUMN+CELL first column=cf:info, timestamp=1435548279711, value=hello hbase second column=cf:name, timestamp=1435548751549, value=zhou third column=cf:nation, timestamp=1435548760826, value=China 3 row(s) in 0.0320 seconds

This command returns all data. The order of the rows returned by HBase is sorted by the row name. HBase is called rowkey ).

5. delete a table
To delete a table, you need to "disable" it before "drop" it. Run the following command:

hbase(main):010:0> disable 'mytable'0 row(s) in 1.2380 secondshbase(main):011:0> drop 'mytable'0 row(s) in 0.1770 secondshbase(main):012:0> listTABLE 0 row(s) in 0.0070 seconds=> []

There are still many tips for HBase, but everything else is based on the above basic operations. You must have a good understanding.

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.