Article From:https://www.cnblogs.com/coffees/p/9967744.html

HBaseThe command line tool, the simplest interface, is suitable for HBase management. You can use shell commands to query the details of data in HBase. After installing HBase, start the Hadoop cluster (using HDFS storage), start zookeeper, and useThe start-hbase.sh command opens the HBase service, and finally executes the HBase shell in the shell to access the command line interface.

  habse shellHelp has a comprehensive introduction to grammar. The operation of HBase shell is divided into 10 categories. This article only introduces the first four commonly used categories: gerneral, ddl, namespace, dml.

  1. Gerneral

  status:Query the current server status

Qianfeng Beijing School Area Sharing - Hbase shell basic operation complete process 335

  Version:View current version

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Process 354

  Whoami:Query the current HBase user

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 377

  Table_help:References to tables, adding and deleting data to a table by obtaining a table reference, etc., are not recommended for use now.

  2. DDL

  Create:Create a table

  ###Create a table named Qianfeng with CF as the column family

  create ‘qianfeng’,‘cf’

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Flow 510

  list:List all tables of HBase

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Process 531

  disable:Disable a table

  ##Disable table’qianfeng’

  disable ‘qianfeng’

  is_disabled:Is the table disabled?

  ##Verify that the table’qianfeng’is disabled

  is_disabled ‘qianfeng’

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Process 657

  enable: Enable a table

  ##Enable table’qianfeng’

  enable ‘qianfeng’

  is_enabled:Is the table enabled?

  ##Verify that the table’qianfeng’is enabled

  is_enabled ‘qianfeng’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 780

  describe:View table description

  ##View the description information of the’qianfeng’table

  describe ‘qianfeng’

Qianfeng Beijing School Area Sharing - Hbase shell basic operation complete process 845

  alter:Modify table structure

  ##Add a column family `cf1’to table `qianfeng’

  alter ‘qianfeng’,‘cf1’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 915

  exists:Verify that the table exists

  ##Verify the existence of the table’qianfeng’

  exists ‘qianfeng’

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Flow 976

  drop:Delete tables. Tables need to be disabled before they can be deleted

  ##Delete the table’qianfeng’

  disable ‘qianfeng’

  drop ‘qianfeng’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 1059

  disable_all:Disable multiple tables

  drop_all:Delete multiple tables. Tables need to be disabled before they can be deleted

  3. Namespace

  create_namespace:Creating a namespace is equivalent to creating a database in a relational database

  ##Create a namespace named’qf’and add attributes

  create_namespace ‘qf’, {‘PROPERTY_NAME’=>‘PROPERTY_VALUE’}

  alter_namespace:Modify, add, and delete namespace attributes

  ##Setting the properties of namespace QF

  alter_namespace ‘qf’, {METHOD => ‘set’, ‘PROPERTY_NAME’ => ‘PROPERTY_VALUE’}

  ##Delete the attributes of namespace QF

  alter_namespace ‘qf’, {METHOD => ‘unset’, NAME=>‘PROPERTY_NAME’}

  describe_namespace:Get a description of the namespace

  ##Get the description information of the namespace’qf’

  describe_namespace ‘qf’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 1545

  drop_namespace:Delete namespace

  ##Delete the namespace’qf’

  drop_namespace ‘qf’

  list_namespace:View all namespaces

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 1634

  list_namespace_tables:View all tables in the namespace

  ##View all tables under namespace’ns1′

  list_namespace_tables‘ns1’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 1722

  4. DML

  First create a table test under the namespace `qianfeng'(if there is no namespace, create the namespace first). The column family is `cf’ for testing.

  create ‘qianfeng:test’,‘cf’

  put:Add cell (data)

  # #Add data to the row key of the table test under namespace Qianfeng for R1 column family

  put ‘qianfeng:test’,‘r1′,‘cf:uname’,‘zhangsan’

  scan:Scan table

  scan ‘qianfeng:test’

Qianfeng Beijing School Area Sharing-Hbase Shell Basic Operation Complete Flow 1970

  get:Get data for a column or cell.

  ##Add data to the row key of the table test under namespace Qianfeng for R1 column family

  put ‘qianfeng:test’,‘r1′,‘cf:age’,‘23′

  ##Get all data with rowkey R1 under column family CF

  get ‘qianfeng:test’,‘r1’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 2129

  ##Get data with rowkey R1 and column name uname under column family CF (get a cell)

  get ‘qianfeng:test’,‘r1′,‘cf:uname’

Qianfeng Beijing School Area Sharing - Hbase shell basic operation complete process 2212

  truncate:Clear the table without disable (just empty the data)

  ##Empty table `qianfeng: test’

  truncate ‘qianfeng:test’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 2298

  Look at all the tables under’qianfeng’

Qianfeng Beijing School Area Sharing-Hbase shell basic operation complete process 2320

  These are the basic operations of HBase shell scripts, which should be mastered skillfully. Learning the Java API of HBase based on mastering the HBase shell script will be twice the result with half the effort.

Leave a Reply

Your email address will not be published. Required fields are marked *