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
- Step 2: Buy an Instance
- Step 3: Connect to the GeminiDB Cassandra Instance
- Basic Syntax
Step 1: Buy a GeminiDB Cassandra Instance
- Log in to the GeminiDB console.
- In the service list, choose Databases > GeminiDB Cassandra API.
- On the Instances page, click Buy DB Instance.
- 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
- View the purchased GeminiDB Cassandra instance.
Figure 3 Successful purchase
Step 2: Buy an Instance
- Log in to the GeminiDB console.
- In the service list, choose > . On the Elastic Cloud Server console, click Buy ECS.
- 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
- 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
- Configure a password for the ECS and click Next: Confirm.
Figure 9 Advanced settings
- Confirm the configurations and click Submit.
Figure 10 Confirming the configurations
- View the purchased ECS.
Step 3: Connect to the GeminiDB Cassandra Instance
- On the ECS console, log in to the ECS using the remote login option.
Figure 11 Remote login
- Enter the username and password of the ECS.
Figure 12 Entering the username and password
- 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.
- Decompress the client package.
unzip Cassandra_cqlsh_x86_64.zip
- Make the files executable:
chmod +x *
- 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.
- If information similar to the following is displayed, the connection was successful.
rwuser@cqlsh>
Basic Syntax
- Keyspace syntax
- Create a keyspace.
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
- Create a keyspace.
- Table syntax
- Create a table.
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,
- 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,
Figure 21 Deleting an entire table
- Create a 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
- Run the HELP command to view all supported commands.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot