Use mysqldump to export database schemas and data from an ApsaraDB for SelectDB instance to a SQL file. The exported file contains CREATE DATABASE, CREATE TABLE, and INSERT statements, making it suitable for backup and small-scale migration.
mysqldump is intended for development, testing, or small-scale data exports only. Do not use it in production environments with large datasets.
Prerequisites
Before you begin, make sure you have:
mysqldump installed (bundled with MySQL client tools)
The connection details for your ApsaraDB for SelectDB instance: host, port, and username
Export data
ApsaraDB for SelectDB does not support MySQL tablespaces. You must include --no-tablespaces in every mysqldump command.
Replace the placeholder values in the examples with your actual connection details:
| Placeholder | Description | Example |
|---|---|---|
<host> | Hostname or IP address of your instance | 127.0.0.1 |
<port> | Port number | 9030 |
<user> | Database username | root |
Export a specific table
mysqldump -h<host> -P<port> -u<user> --no-tablespaces --databases test_db --tables test_tableExport the schema only (no data)
mysqldump -h<host> -P<port> -u<user> --no-tablespaces --databases test_db --tables test_table --no-dataExport all tables in one or more databases
mysqldump -h<host> -P<port> -u<user> --no-tablespaces --databases test_db1 test_db2Export all databases
mysqldump -h<host> -P<port> -u<user> --no-tablespaces --all-databasesImport data
To import a mysqldump file into an ApsaraDB for SelectDB instance:
Export data to a file:
mysqldump -h<host> -P<port> -u<user> --no-tablespaces --all-databases > all_databases.sqlConnect to your ApsaraDB for SelectDB instance using the MySQL client, then run:
source all_databases.sql