All Products
Search
Document Center

AnalyticDB:Export data to a self-managed MySQL database

Last Updated:Mar 28, 2026

AnalyticDB for MySQL Data Warehouse Edition (V3.0) lets you export data to a self-managed MySQL database hosted on an Elastic Compute Service (ECS) instance. The export uses an external table as a bridge: you create the external table to point to the destination MySQL database, then write data to it with a single SQL statement.

Prerequisites

Before you begin, ensure that you have:

  • An ECS instance in the same virtual private cloud (VPC) and region as the AnalyticDB for MySQL cluster

  • A self-managed MySQL database hosted on that ECS instance

  • The MySQL port (typically 3306) authorized for inbound traffic in the ECS security group rules. For details, see Add a security group rule

  • Test data ready to export

  • (Required for elastic mode) ENI turned on in the Network Information section of the Cluster Information page

Example setup used in this guide:

The destination is an ECS-hosted MySQL database named test_adb, with a courses table created as follows:

CREATE TABLE courses (
    id bigint NOT NULL,
    name varchar(32) NOT NULL,
    grade varchar(32) NOT NULL,
    submission_date  timestamp NOT NULL,
    PRIMARY KEY (id)
);

Export data using an external table

This procedure creates a source table in AnalyticDB for MySQL, creates an external table mapped to the destination MySQL database, and then writes data to the external table.

Step 1: Connect to the AnalyticDB for MySQL cluster

Connect to your cluster. For details, see Connect to an AnalyticDB for MySQL cluster.

Step 2: Create a source database

Create a database in the cluster to hold the data you want to export. For details, see Create a database.

This guide uses a database named adb_demo.

Step 3: Create a source table and insert data

Run the following statement to create a courses table in adb_demo:

CREATE TABLE courses (
    id bigint AUTO_INCREMENT,
    name varchar NOT NULL,
    grade varchar DEFAULT '1st Grade',
    submission_date timestamp
) DISTRIBUTED BY HASH(id);

Insert a row of test data:

INSERT INTO courses (name,submission_date) VALUES("Jams",NOW());

Step 4: Create an external table

The external table maps to the destination MySQL database. Run the following statement to create an external table named courses_external_table in adb_demo:

CREATE TABLE IF NOT EXISTS courses_external_table(
 id bigint NOT NULL,
 name varchar(32) NOT NULL,
 grade varchar(32) NOT NULL,
 submission_date  timestamp NOT NULL,
 PRIMARY KEY (id)
 )
ENGINE='mysql'
TABLE_PROPERTIES='{
"url":"jdbc:mysql://mysql-vpc-address:3306/test_adb",
"tablename":"courses",
"username":"mysql-user-name",
"password":"mysql-user-password",
"charset":"utf8"
}';

Required parameters:

ParameterDescription
ENGINE='mysql'The storage engine for the external table. Set to mysql to connect to a MySQL database.
TABLE_PROPERTIESThe connection information used by the AnalyticDB for MySQL cluster to access data in the ECS-hosted self-managed MySQL database.
urlThe JDBC URL of the destination MySQL database, using the primary private IP address or the VPC endpoint of the ECS instance. Format: jdbc:mysql://<primary-private-ip>:3306/<database-name>. Example: jdbc:mysql://192.168.128.***:3306/test_adb. To find the primary private IP address of your ECS instance, open the ECS console, select the instance, and check Primary Private IP Address in the Network Information section of the Instance Details tab.
tablenameThe name of the destination table in the MySQL database.
usernameThe username of the database account used to connect to the MySQL database.
passwordThe password of the database account.

Optional parameters:

ParameterDefaultDescription
charsetutf8The character set of the source database. Valid values: gbk, utf8, utf8mb4.

Step 5: Export the data

Run the following statement to write data from the source table to the destination MySQL database through the external table:

REPLACE INTO courses_external_table
SELECT * FROM courses;

Verify the export

Connect to the test_adb MySQL database and run:

SELECT * FROM courses LIMIT 100;

Confirm the exported rows appear in the courses destination table.

Troubleshooting

Cannot connect to the MySQL database

The most common cause is a missing or incorrect security group rule on the ECS instance. Check that port 3306 is authorized for inbound traffic from your AnalyticDB for MySQL cluster. See Add a security group rule.

If the port is open but the connection still fails:

  • Verify that the url in TABLE_PROPERTIES uses the Primary Private IP Address of the ECS instance, not the public IP.

  • Verify that username and password are correct.

  • Verify that the JDBC URL format is jdbc:mysql://<ip>:3306/<database-name> with no trailing slash or extra characters.

No data appears in the destination table after export

Run SELECT * FROM courses LIMIT 10; in the AnalyticDB for MySQL cluster to confirm the source table contains data before running REPLACE INTO.

Also verify that the schema of courses_external_table matches the destination table in test_adb. Mismatched column types or names can cause the write to fail or raise an error.

What's next

To import data from a self-managed MySQL database into AnalyticDB for MySQL, create an external table with the same ENGINE='mysql' syntax and use INSERT INTO ... SELECT * to read from it.