Use a Java Database Connectivity (JDBC) catalog to read data from StarRocks and write it into ApsaraDB for SelectDB.
Prerequisites
Before you begin, make sure:
All nodes in the StarRocks cluster and the SelectDB instance are in the same Virtual Private Cloud (VPC). If they are not, resolve the network connectivity issue first. For details, see How do I resolve network connectivity issues between an ApsaraDB for SelectDB instance and a data source?
The StarRocks instance IP address is added to the SelectDB whitelist. For details, see Configure a whitelist
If the StarRocks instance has a whitelist, the SelectDB instance IP address CIDR block is added to that whitelist:
To find the SelectDB VPC IP address, see How do I view the IP addresses in the VPC to which my ApsaraDB SelectDB instance belongs?
To find the SelectDB public IP address, run
pingagainst the public endpoint
You understand what a catalog is and how to use it. For details, see Data lakehouse
Example environment
The steps below migrate data from the SR_t table in the starRocks_db StarRocks database to the test_SR2SelectDB table in the test_db SelectDB database. Adjust the names to match your setup.
| Role | Value |
|---|---|
| Source database | starRocks_db |
| Source table | SR_t |
| Destination database | test_db |
| Destination table | test_SR2SelectDB |
Prepare source data
Run the following statements on your StarRocks instance to create a sample database, table, and records.
-- Create a database
CREATE DATABASE starRocks_db;
-- Create a table
CREATE TABLE SR_t
(
id int,
name string,
age int
)
DISTRIBUTED BY HASH(id) BUCKETS 4
PROPERTIES("replication_num" = "1");
-- Insert sample records
INSERT INTO SR_t VALUES
(1, 'Alice', 25),
(2, 'Bob', 30),
(3, 'Charlie', 35),
(4, 'David', 40),
(5, 'Eve', 45);Migrate data
Step 1: Connect to SelectDB
Connect to the SelectDB instance using a MySQL client. For details, see Connect to an instance.
The SWITCH statement does not work when connecting through Data Management Service (DMS). Use a MySQL client.
Step 2: Create a StarRocks JDBC catalog
Create a catalog that points to your StarRocks instance. SelectDB uses JDBC to read data from the external source.
CREATE CATALOG starrocks_catalog PROPERTIES (
"type"="jdbc",
"user"="root",
"password"="123456",
"jdbc_url" = "jdbc:mysql://127.0.0.1:3306/demo",
"driver_url" = "mysql-connector-java-8.0.25.jar",
"driver_class" = "com.mysql.cj.jdbc.Driver",
"checksum" = "fdf55dcef04b09f2eaf42b75e61ccc9a"
)For a description of each parameter, see Catalog parameters.
Step 3: Verify the catalog
Run SHOW CATALOGS to confirm the catalog was created.
SHOW CATALOGS;Expected output:
+--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+
| CatalogId | CatalogName | Type | IsCurrent | CreateTime | LastUpdateTime | Comment |
+--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+
| 436009309195 | starrocks_catalog | jdbc | | 2024-08-06 17:09:08.058 | 2024-07-19 18:04:37 | |
| 0 | internal | internal | yes | UNRECORDED | NULL | Doris internal catalog |
+--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+Step 4: Set up the destination
Create the destination database and table.
-- (Optional) Create the destination database if it doesn't exist
CREATE DATABASE test_db;
-- Switch to the destination database
USE test_db;
-- Create the destination table
-- Column types must match the corresponding StarRocks column types. See Type mapping.
CREATE TABLE test_SR2SelectDB
(
id int,
name string,
age int
)
DISTRIBUTED BY HASH(id) BUCKETS 4
PROPERTIES("replication_num" = "1");For column type mapping between StarRocks and SelectDB, see Type mapping.
Step 5: Copy the data
You can view and access data in the starrocks_catalog external catalog in the same way as you access data in an internal catalog.
ApsaraDB for SelectDB supports read-only access to external catalog data. Write operations on external catalog data are not supported.
Run the migration:
INSERT INTO test_SR2SelectDB SELECT * FROM doris_catalog.SR_db.SR_t;Step 6: Verify the migrated data
SELECT * FROM test_SR2SelectDB;Confirm that the row count and data match the source table.
Prerequisites
Before you begin, make sure:
All nodes in the StarRocks cluster and the SelectDB instance are in the same Virtual Private Cloud (VPC). If they are not, resolve the network connectivity issue first. For details, see How do I resolve network connectivity issues between an ApsaraDB for SelectDB instance and a data source?
The StarRocks instance IP address is added to the SelectDB whitelist. For details, see Configure a whitelist
If the StarRocks instance has a whitelist, the SelectDB instance IP address CIDR block is added to that whitelist:
To find the SelectDB VPC IP address, see How do I view the IP addresses in the VPC to which my ApsaraDB SelectDB instance belongs?
To find the SelectDB public IP address, run
pingagainst the public endpoint
You understand what a catalog is and how to use it. For details, see Data lakehouse
Example environment
This example shows how to migrate data from the `SR_t` table in the `starRocks_db` StarRocks database to the `test_SR2SelectDB` table in the `test_db` SelectDB database. You can modify the parameters as needed. The sample environment is as follows:
Destination database: test_db
Destination table: test_SR2SelectDB
Source database: starRocks_db
Source table: SR_t
Example: Prepare the source data
Log on to your StarRocks data source and perform the following steps.
Create a database.
CREATE DATABASE starRocks_db;Create a table.
CREATE TABLE SR_t ( id int, name string, age int ) DISTRIBUTED BY HASH(id) BUCKETS 4 PROPERTIES("replication_num" = "1");Insert data.
INSERT INTO SR_t VALUES (1, 'Alice', 25), (2, 'Bob', 30), (3, 'Charlie', 35), (4, 'David', 40), (5, 'Eve', 45);
Procedure
Connect to the SelectDB instance. For more information, see Connect to an instance.
NoteThe
SWITCHinstruction does not work when you log on using DMS. You must connect using a MySQL client.You can create a StarRocks Java Database Connectivity (JDBC) catalog. For more information, see JDBC data sources.
CREATE CATALOG starrocks_catalog PROPERTIES ( "type"="jdbc", "user"="root", "password"="123456", "jdbc_url" = "jdbc:mysql://127.0.0.1:3306/demo", "driver_url" = "mysql-connector-java-8.0.25.jar", "driver_class" = "com.mysql.cj.jdbc.Driver", "checksum" = "fdf55dcef04b09f2eaf42b75e61ccc9a" )Parameters
Parameter
Required
Default value
Description
user
Yes
None
The username for the StarRocks database.
password
Yes
None
The password for the StarRocks database.
jdbc_url
Yes
None
The JDBC connection string. It must contain the endpoint of the StarRocks database.
driver_url
Yes
None
The name of the JDBC driver JAR package.
NoteUse
mysql-connector-java-8.0.25.jar.To use a different JAR package, submit a ticket.
driver_class
Yes
None
The class name of the JDBC driver.
Set this parameter to
com.mysql.cj.jdbc.Driver.lower_case_table_names
(Renamed to `lower_case_meta_names` in version 4.0)
No
"false"
Specifies whether to synchronize the names of databases and tables from the external JDBC data source in lowercase.
true: You can query databases and tables with names that are not in lowercase by maintaining a mapping from lowercase names to the actual names in the remote system. In this case, the names of databases, tables, and columns are converted to lowercase.
false: You cannot query databases and tables with names that are not in lowercase.
ImportantFor SelectDB 3.0:
If the
lower_case_table_namesparameter of the frontend (FE) is set to1or2, you must set thelower_case_table_namesparameter of the Catalog totrue.If the
lower_case_table_namesparameter of the FE is set to0, the Catalog parameter can betrueorfalse.
For SelectDB 4.0:
If the
lower_case_table_namesparameter of the FE is0or2, the names of databases, tables, and columns are not converted.If the
lower_case_table_namesparameter of the FE is1, table names are converted to lowercase, but database and column names are not.
only_specified_database
No
"false"
Specifies whether to synchronize only the specified database.
true: Synchronizes only the database specified in the JDBC URL.
false: Synchronizes all databases in the JDBC URL.
include_database_list
No
""
When
only_specified_database=true, this parameter specifies multiple databases to synchronize. Separate database names with commas (,). Database names are case-sensitive.exclude_database_list
No
""
When
only_specified_database=true, this parameter specifies multiple databases to exclude from synchronization. Separate database names with commas (,). Database names are case-sensitive.meta_names_mapping
No
""
If an external data source has names that differ only in case, such as `DORIS` and `doris`, querying the Catalog may cause an error due to ambiguity. In this case, configure the
meta_names_mappingparameter to resolve the conflict.For more information, see Case sensitivity settings.
ImportantThis parameter applies only to SelectDB 4.0.
You can view the Catalogs.
SHOW CATALOGS; -- Check if the Catalog was created successfully.The result is as follows.
+--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+ | CatalogId | CatalogName | Type | IsCurrent | CreateTime | LastUpdateTime | Comment | +--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+ | 436009309195 | starrocks_catalog | jdbc | | 2024-08-06 17:09:08.058 | 2024-07-19 18:04:37 | | | 0 | internal | internal | yes | UNRECORDED | NULL | Doris internal catalog | +--------------+-------------------+----------+-----------+-------------------------+---------------------+------------------------+(Optional) Switch to the External Catalog folder SR_catalog.
You can view and access data in the `starrocks_catalog` external catalog in the same way as you access data in an internal catalog.
NoteCurrently, ApsaraDB for SelectDB supports only read operations on data in external catalogs.
SWITCH SR_catalog;(Optional) Switch to the `internal` internal catalog.
If you did not perform the previous step, skip this step.
SWITCH internal;(Optional) Create a database.
If you have already created the destination database, skip this step.
CREATE database test_db;Switch to the destination database.
USE test_db;Create a table.
If a destination table already exists, verify that the data types of the target columns correspond to the data types of the source columns in StarRocks.
If a destination table does not exist, ensure that the data types of the target columns correspond to the data types of the source columns in StarRocks when you create the table.
For more information about column mapping, see Type mapping.
CREATE TABLE test_SR2SelectDB ( id int, name string, age int ) DISTRIBUTED BY HASH(id) BUCKETS 4 PROPERTIES("replication_num" = "1");Migrate the data.
INSERT INTO test_SR2SelectDB SELECT * FROM doris_catalog.SR_db.SR_t;Verify the imported data.
SELECT * FROM test_SR2SelectDB;
Migrate incremental data
In production, StarRocks data typically includes both historical and ongoing writes. Two common strategies for keeping SelectDB in sync:
Concurrent write: When your application writes new records to StarRocks, write the same records to SelectDB at the same time.
Periodic job: Schedule a job to read partitioned data from StarRocks and write it to SelectDB at regular intervals.
Catalog parameters
The following table describes the parameters in the CREATE CATALOG statement. For the full parameter reference, see JDBC data sources.
| Parameter | Required | Default | Description |
|---|---|---|---|
user | Yes | — | Username for the StarRocks database |
password | Yes | — | Password for the StarRocks database |
jdbc_url | Yes | — | JDBC connection string. Must include the StarRocks endpoint. |
driver_url | Yes | — | Name of the JDBC driver JAR file. Use mysql-connector-java-8.0.25.jar. To use a different JAR, submit a ticket. |
driver_class | Yes | — | Driver class name. Set to com.mysql.cj.jdbc.Driver. |
lower_case_table_names (renamed to lower_case_meta_names in SelectDB 4.0) | No | "false" | Whether to synchronize database and table names in lowercase. See Case sensitivity settings. |
only_specified_database | No | "false" | true: sync only the database in the JDBC URL. false: sync all databases. |
include_database_list | No | "" | When only_specified_database=true, the comma-separated list of databases to sync. Case-sensitive. |
exclude_database_list | No | "" | When only_specified_database=true, the comma-separated list of databases to exclude. Case-sensitive. |
meta_names_mapping | No | "" | Resolves name conflicts caused by case differences (for example, DORIS and doris). Applies to SelectDB 4.0 only. See Case sensitivity settings. |
Case sensitivity settings
SelectDB 3.0
The behavior of lower_case_table_names depends on the frontend (FE) configuration:
FE lower_case_table_names value | Catalog lower_case_table_names value |
|---|---|
1 or 2 | Must be true |
0 | Can be true or false |
SelectDB 4.0 (parameter renamed to lower_case_meta_names)
FE lower_case_table_names value | Effect |
|---|---|
0 or 2 | Database, table, and column names are not converted |
1 | Table names are converted to lowercase; database and column names are not |
What's next
JDBC data sources — full parameter reference and supported data sources
Type mapping — StarRocks-to-SelectDB column type mapping
Data lakehouse — catalog concepts and operations