Updated on 2022-11-18 GMT+08:00

Phoenix Command Line

Phoenix supports SQL statements to operate HBase. The following describes how to use SQL statements to create tables, insert data, query data, and delete tables.

Prerequisites

The HBase client has been installed. For example, the client has been installed in the /opt/client directory. The client directory in the following operations is only an example. Change it based on the actual installation directory onsite. Before using the client, download and update the client configuration file, and ensure that the active management node of Manager is available.

Procedure

  1. Optional: Log in to the node where the client is installed as the client installation user.

    Access the HBase client installation directory:

    cd /opt/client

  2. Run the following command to configure environment variables:

    source bigdata_env

  3. If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the current user. The current user must have the permission to create HBase tables. If Kerberos authentication is disabled for the current cluster, skip this step:

    kinit MRS cluster user

    For example, kinit hbaseuser.

  4. Running Commands on the Phoenix Client.

    sqlline.py

  5. Create a table:

    CREATE TABLE TEST (id VARCHAR PRIMARY KEY, name VARCHAR);

  6. Insert data:

    UPSERT INTO TEST(id,name) VALUES ('1','jamee');

  7. Query data:

    SELECT * FROM TEST;

  8. Deleting a table:

    DROP TABLE TEST;

  9. Exit the Phoenix CLI:

    !quit