Scenarios
You can use an ECS or local device to connect to a GeminiDB instance over a public network.
This section describes how to use a Linux ECS to connect to a GeminiDB Cassandra instance over a public network.
Prerequisites
- Bind an EIP to the GeminiDB Cassandra instance node and set security group rules.
- Create an ECS running Linux. For details, see "Creating ECSs" in ECS User Guide.
- Obtain the Cassandra client installation package from the Cassandra official website.
- Before using this tool, install the Python dependency package cassandra-driver 3.11.0 or later.
Connecting to a DB Instance Through a Cassandra Client
- Log in to the ECS. For details, see the section "Logging In to an ECS" in the Elastic Cloud Server User Guide.
- Upload the Cassandra client installation package to ECS.
- Obtain the client tool cqlsh.
- Connect to the DB instance in the directory where the cqlsh tool is located.
./cqlsh <DB_HOST> <DB_PORT> -u <DB_USER>
Example:
./cqlsh 192.168.1.8 8635 -u rwuser
- <DB_HOST> indicates the EIP of the node to be connected. Obtain the value from the EIP column in the node list on the Basic Information page.
- <DB_PORT> indicates the port number. The default value is 8635 and cannot be changed.
- <DB_USER> indicates the database account name. The default value is rwuser.
- Check the connection result. If the following information is displayed, the connection is successful.
rwuser@cqlsh>
Follow-up Operations
After logging in to the GeminiDB Cassandra instance, you can perform the following operations:
- Run the HELP command to view all supported commands.
- Run HELP <COMMAND> to query the usage of a command. Example: HELP DESC
- Keyspace syntax
- Create a keyspace. Example:
CREATE KEYSPACE IF NOT EXISTS test_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'};
Set the keyspace name to test_keyspace, replication to SimpleStrategy, and number of replicas to 3.
- Run DESC <keyspace_name> to verify the creation results.
- Run use <keyspace_name> to switch to the keyspace you created.
- Run DROP KEYSPACE <keyspace_name> to delete the keyspace you created.
- Table syntax
- Create a table. Example:
CREATE TABLE test_table(user_id int, age int, user_name text, PRIMARY KEY(user_id));
test_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.
- Insert data into the table. Example:
INSERT INTO test_table (user_id, age, user_name) VALUES (1, 10, 'user1');
INSERT INTO test_table (user_id, age, user_name) VALUES (2, 20, 'user2');
INSERT INTO test_table (user_id, age, user_name) VALUES (3, 30, 'user3');
- Run SELECT * FROM <table_name> to query table data.
- Add a column to the table. Example:
ALTER TABLE test_table ADD gender text;
- Update data in a table of a keyspace. Example:
UPDATE test_keyspace.test_table SET prename = 'user_prename1' WHERE user_id = 1;
UPDATE test_keyspace.test_table SET prename = 'user_prename2' WHERE user_id = 2;
UPDATE test_keyspace.test_table SET prename = 'user_prename3' WHERE user_id = 3;
- Delete data from a table in a keyspace. Example:
Delete the age data of the user whose ID is 1.
DELETE age FROM test_keyspace.test_table WHERE user_id=1;
Delete the entire record of the user whose ID is 2.
DELETE FROM test_keyspace.test_table WHERE user_id=2;
- Clear all records in the table. Example:
TRUNCATE test_keyspace.test_table;
- Delete the entire table. Example:
DROP TABLE test_keyspace.test_table;