This guide walks you through creating a database in ApsaraDB for SelectDB, loading data into it with Stream Load, and verifying the result with a query — a complete end-to-end workflow in five steps.
Prerequisites
Before you begin, ensure that you have:
Connected to an ApsaraDB for SelectDB instance over the MySQL protocol. For instructions, see Connect to an instance
Usage notes
Each ApsaraDB for SelectDB instance supports up to 256 databases.
ApsaraDB for SelectDB is compatible with standard SQL syntax. See the SQL reference for details.
Procedure
Step 1: Create a database
Run the following statement to create a database named test_db:
CREATE DATABASE test_db;Step 2: Create a table
Run the following statements to switch to test_db and create a table named test_table:
USE test_db;
CREATE TABLE test_table
(
k1 TINYINT,
k2 DECIMAL(10, 2) DEFAULT "10.05",
k3 CHAR(10) COMMENT "string column",
k4 INT NOT NULL DEFAULT "1" COMMENT "int column"
)
COMMENT "my first table"
DISTRIBUTED BY HASH(k1) BUCKETS 16;Step 3: Prepare sample data
Save the following content as a local file named data.csv:
1,0.14,a1,20
2,1.04,b2,21
3,3.14,c3,22
4,4.35,d4,23Step 4: Load data with Stream Load
Stream Load submits an import request over HTTP. Run the following curl command from your local machine to load data.csv into test_table:
curl --location-trusted -u admin:admin_123 -H "label:123" -H "column_separator:," -T data.csv http://<host>:<port>/api/test_db/test_table/_stream_loadWhere:
| Parameter | Description |
|---|---|
<host> | The virtual private cloud (VPC) endpoint or public endpoint of the instance. To apply for a public endpoint, see Apply for or release a public endpoint. |
<port> | The HTTP port number of the instance. |
label | A unique identifier for this import task, used for idempotency. |
column_separator | The column delimiter in the data file. Set to , for CSV files. |
Find the endpoint and HTTP port on the instance details page in the ApsaraDB for SelectDB console.
For more information about Stream Load, see Import data by using Stream Load.
Step 5: Verify the data
Run the following query to confirm the data was loaded correctly:
SELECT * FROM test_table;The expected output:
+------+------+------+------+
| k1 | k2 | k3 | k4 |
+------+------+------+------+
| 1 | 0.14 | a1 | 20 |
| 2 | 1.04 | b2 | 21 |
| 3 | 3.14 | c3 | 22 |
| 4 | 4.35 | d4 | 23 |
+------+------+------+------+What's next
Import data by using Stream Load — load larger datasets and explore advanced parameters
SQL reference — explore the full SQL syntax supported by ApsaraDB for SelectDB