Help Center/ GeminiDB/ GeminiDB Cassandra API/ Best Practices/ Buying and Connecting to a GeminiDB Cassandra Instance
Updated on 2024-10-08 GMT+08:00

Buying and Connecting to a GeminiDB Cassandra Instance

This section describes how to buy a GeminiDB Cassandra instance and uses a Linux ECS as an example to describe how to connect to the instance over a private network.

Step 1: Buy a GeminiDB Cassandra Instance

  1. Log in to the GeminiDB console.
  2. In the service list, choose Databases > GeminiDB Cassandra API.
  3. On the Instances page, click Buy DB Instance.
  4. Click Buy DB Instance, select a billing mode, and configure instance parameters. Then, click Next and complete subsequent operations.

    Figure 1 Basic information

    Figure 2 Setting a password

  5. View the purchased GeminiDB Cassandra instance.

    Figure 3 Successful purchase

Step 2: Buy an Instance

  1. Log in to the GeminiDB console.
  2. In the service list, choose Compute > Elastic Cloud Server. On the Elastic Cloud Server console, click Buy ECS.

  3. Configure basic settings and click Next: Configure Network. Make sure that the ECS is in the same region, AZ, VPC, and security group as the GeminiDB Cassandra instance you created.

    Figure 4 Basic settings
    Figure 5 Selecting specifications
    Figure 6 Selecting an image

  4. Configure the ECS network and click Next: Configure Advanced Settings. Make sure that the ECS is in the same VPC and security group as the GeminiDB Cassandra instance.

    • If security group rules allow access from the ECS, you can connect to the instance using the ECS.
    • If the security group rules do not allow access from the ECS, add an inbound rule to the security group.
    Figure 7 Network settings
    Figure 8 Selecting an EIP

  5. Configure a password for the ECS and click Next: Confirm.

    Figure 9 Advanced settings

  6. Confirm the configurations and click Submit.

    Figure 10 Confirming the configurations

  7. View the purchased ECS.

Step 3: Connect to the GeminiDB Cassandra Instance

  1. On the ECS console, log in to the ECS using the remote login option.

    Figure 11 Remote login

  2. Enter the username and password of the ECS.

    Figure 12 Entering the username and password

  3. Download the Cassandra installation package and upload it to the ECS.

    Method 1:

    wget https://dbs-download.obs.cn-north-1.myhuaweicloud.com/nosql/Cassandra_cqlsh_x86_64.zip

    Method 2:

    Download the Cassandra client installation package using your browser and upload it to the ECS.

  4. Decompress the client package.

    unzip Cassandra_cqlsh_x86_64.zip

  5. Make the files executable:

    chmod +x *

  6. Connect to the GeminiDB Cassandra instance in the directory where the cqlsh is located.

    ./cqlsh <DB_HOST> <DB_PORT> -u <DB_USER>

    Example:

    ./cqlsh 192.xx.xx.xx 8635 -u rwuser

    Table 1 Required description

    Parameter

    Description

    <DB_HOST>

    The private IP address of the instance to be accessed.

    To obtain this IP address, go to the Instances page, locate the instance, and click its name. The IP address can be found in the Private IP Address field under Node Information on the Basic Information page.

    If the GeminiDB Cassandra instance you purchased has multiple nodes, select the private IP address of any node.

    <DB_PORT>

    The port used to access the instance. The default port number is 8635. Set this parameter based on service requirements.

    Click the instance name to go to the Basic Information page and obtain the port number in the Network Information area.

    <DB_USER>

    Username of the instance administrator. The default value is rwuser.

  7. If information similar to the following is displayed, the connection was successful.

    rwuser@cqlsh>

Basic Syntax

  • Keyspace syntax
    • Create a keyspace.

      Example:

      CREATE KEYSPACE IF NOT EXISTS nosql WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'};

      In this example, keyspace_name is set to nosql, class to SimpleStrategy, and replication_factor to 3. GeminiDB Cassandra provides strong consistency and 3 data copies for each GeminiDB Cassandra instance no matter how many copies you set.

    • Run DESC <keyspace_name> to verify the creation results.
      Figure 13 Verifying the creation results
    • Run use <keyspace_name> to switch to the keyspace you created.
      Figure 14 Switching the keyspace
    • Run DROP KEYSPACE <keyspace_name> to delete the keyspace you created.
      Figure 15 Deleting the keyspace
  • Table syntax
    • Create a table.

      Example:

      CREATE TABLE nosql_table(user_id int, age int, user_name text, PRIMARY KEY(user_id));

      nosql_table is a table name defined by the following three columns: user_id, age, and user_name. user_id indicates a user ID of the INT data type. age indicates user age of the INT data type. user_name indicates a username of the TEXT data type. The primary key is user_id.

    • Run DESC <table_name> to verify the creation results.
      Figure 16 Verifying the creation results
    • Insert data into the table, for example,

      INSERT INTO nosql_table (user_id, age, user_name) VALUES (1, 10, 'user1');

      INSERT INTO nosql_table (user_id, age, user_name) VALUES (2, 20, 'user2');

      INSERT INTO nosql_table (user_id, age, user_name) VALUES (3, 30, 'user3');

    • Run SELECT * FROM <table_name> to query table data.
      Figure 17 Querying table data
    • Add a column to the table, for example,

      ALTER TABLE nosql_table ADD gender text;

    • Update data in a table of a keyspace, for example,

      UPDATE nosql.nosql_table SET gender = 'male' WHERE user_id = 1;

      UPDATE nosql.nosql_table SET gender = 'male' WHERE user_id = 2;

      UPDATE nosql.nosql_table SET gender = 'female' WHERE user_id = 3;

      Figure 18 Viewing the update results
    • Delete data from a table in a keyspace, for example,

      Delete age data of the user whose ID is 1.

      DELETE age FROM nosql.nosql_table WHERE user_id=1;

      Figure 19 Deleting a data record

      Delete the entire record of the user whose ID is 2.

      DELETE FROM nosql.nosql_table WHERE user_id=2;

      Figure 20 Deleting the entire record
    • Delete an entire table, for example,

      DROP TABLE nosql.nosql_table;

      Figure 21 Deleting an entire table
  • HELP command
    • Run the HELP command to view all supported commands.
      Figure 22 Viewing all supported commands
    • HELP <COMMAND> is used to query the usage of a command.

      Example: HELP DESC