This guide walks you through connecting to a StarRocks cluster in E-MapReduce (EMR), creating a database and table, loading test data, and running a query — confirming the cluster is ready to use.
Prerequisites
Before you begin, ensure that you have:
-
A StarRocks cluster. See Create a StarRocks cluster
Log on to the master node
Log on to the master node of the StarRocks cluster via SSH. See Log on to a cluster for details.
All commands in this guide must be run inside an active SSH session on the master node. They cannot be run directly from your local machine.
Connect to the StarRocks cluster
Run the following command to connect to StarRocks using the MySQL client:
mysql -h127.0.0.1 -P 9030 -uroot
| Flag | Value | Description |
|---|---|---|
-h |
127.0.0.1 |
Host — the master node loopback address |
-P |
9030 |
StarRocks query port |
-u |
root |
Username |
Create a database and table
-
Create a database named
load_testand switch to it:CREATE DATABASE IF NOT EXISTS load_test; USE load_test; -
Create a table named
insert_wiki_edit:CREATE TABLE insert_wiki_edit ( event_time DATETIME, channel VARCHAR(32) DEFAULT '', user VARCHAR(128) DEFAULT '', is_anonymous TINYINT DEFAULT '0', is_minor TINYINT DEFAULT '0', is_new TINYINT DEFAULT '0', is_robot TINYINT DEFAULT '0', is_unpatrolled TINYINT DEFAULT '0', delta INT SUM DEFAULT '0', added INT SUM DEFAULT '0', deleted INT SUM DEFAULT '0' ) AGGREGATE KEY(event_time, channel, user, is_anonymous, is_minor, is_new, is_robot, is_unpatrolled) PARTITION BY RANGE(event_time) ( PARTITION p06 VALUES LESS THAN ('2015-09-12 06:00:00'), PARTITION p12 VALUES LESS THAN ('2015-09-12 12:00:00'), PARTITION p18 VALUES LESS THAN ('2015-09-12 18:00:00'), PARTITION p24 VALUES LESS THAN ('2015-09-13 00:00:00') ) DISTRIBUTED BY HASH(user) BUCKETS 10 PROPERTIES("replication_num" = "1");This table uses the AGGREGATE KEY model, partitioned by
event_timerange and distributed byuserhash across 10 buckets.
Load test data
Insert two sample rows into the table:
INSERT INTO insert_wiki_edit VALUES("2015-09-12 00:00:00","#en.wikipedia","GELongstreet",0,0,0,0,0,36,36,0),("2015-09-12 00:00:00","#ca.wikipedia","PereBot",0,1,0,1,0,17,17,0);
The expected output is:
Query OK, 2 rows affected
Query the data
Run a SELECT query to verify the imported data:
select * from insert_wiki_edit;
The expected output is:
+---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+
| event_time | channel | user | is_anonymous | is_minor | is_new | is_robot | is_unpatrolled | delta | added | deleted |
+---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+
| 2015-09-12 00:00:00 | #en.wikipedia | GELongstreet | 0 | 0 | 0 | 0 | 0 | 36 | 36 | 0 |
| 2015-09-12 00:00:00 | #ca.wikipedia | PereBot | 0 | 1 | 0 | 1 | 0 | 17 | 17 | 0 |
+---------------------+---------------+--------------+--------------+----------+--------+----------+----------------+-------+-------+---------+
2 rows in set (0.16 sec)
What's next
Now that you have verified the cluster works end-to-end, explore these topics to continue:
-
Learn about other data loading methods in StarRocks, such as Stream Load and Broker Load
-
Explore StarRocks query acceleration features
-
Monitor your StarRocks cluster status in the EMR console