All Products
Search
Document Center

ApsaraDB RDS:Migrate a self-managed MariaDB to the cloud with mysqldump

Last Updated:Mar 30, 2026

ApsaraDB RDS for MariaDB is fully compatible with native MariaDB, so migrating data follows the same process as moving data between two MariaDB servers. This topic walks you through the complete migration using mysqldump: export table data and stored procedures from your self-managed database, then import them into an RDS instance.

The examples in this topic use a source database running on Linux 7 with MariaDB 10.2.4.

After migration, all table names are stored in lowercase and are case-insensitive on the RDS instance.

Prerequisites

Before you begin, ensure that you have:

Migrate data

Step 1: Create the destination database

Log on to the RDS instance using a remote connection tool and create an empty database to receive the migrated data. For example, create a database named test001

Step 2: Export the data file

Important

Do not write to the source database while the export is in progress. Concurrent writes can cause inconsistent data in the dump file.

On the on-premises database server, run mysqldump to export table data to a SQL file. This command excludes stored procedures, triggers, and functions — those are exported separately in Step 3.

mysqldump -h localhost -u <username> -p --opt --default-character-set=utf8 --hex-blob <db_name> --skip-triggers > /tmp/<db_name>.sql

Replace the placeholders with your values:

Placeholder Description Example
<username> Username of the self-managed database account user
<db_name> Name of the self-managed database to export testdb

Example:

mysqldump -h localhost -u user -p --opt --default-character-set=utf8 --hex-blob testdb --skip-triggers > /tmp/testdb.sql
The database account must have the required permissions to run mysqldump. For the full list of required permissions, see the mysqldump reference.

Step 3: Export stored procedures, triggers, and functions

If your database contains stored procedures, triggers, or functions, export them to a separate file. The sed command strips the DEFINER clause, which is required for compatibility with ApsaraDB RDS for MariaDB.

mysqldump -h localhost -u <username> -p --opt --default-character-set=utf8 --hex-blob <db_name> -R | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > /tmp/<db_name>_trigger.sql

Example:

mysqldump -h localhost -u user -p --opt --default-character-set=utf8 --hex-blob testdb -R | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > /tmp/testdb_trigger.sql
Skip this step if the source database has no stored procedures, triggers, or functions.

Step 4: Import into the RDS instance

Run the following commands to import the data file and then the stored procedure file into the destination database. Import the data file first.

mysql -h <endpoint> -P <port> -u <username> -p <dest_db> < /tmp/<db_name>.sql
mysql -h <endpoint> -P <port> -u <username> -p <dest_db> < /tmp/<db_name>_trigger.sql

Replace the placeholders with your values:

Placeholder Description Example
<endpoint> Public endpoint of the RDS instance rm-bpxxxxx.mariadb.rds.aliyuncs.com
<port> Public port of the RDS instance 3306
<username> Username of the privileged account on the RDS instance testuser
<dest_db> Name of the destination database on the RDS instance test001
<db_name> Name of the self-managed database (used in the file path) testdb

Example:

mysql -h rm-bpxxxxx.mariadb.rds.aliyuncs.com -P 3306 -u testuser -p test001 < /tmp/testdb.sql
mysql -h rm-bpxxxxx.mariadb.rds.aliyuncs.com -P 3306 -u testuser -p test001 < /tmp/testdb_trigger.sql

Step 5: Verify the migration

Refresh the remote connection tool and check the tables in the destination database. If the tables are present and contain data, the migration is complete.