Migrate data from MySQL/MongoDB to CloudBase Database
Migration Notes
This article covers migrating from MySQL and MongoDB to CloudBase Database. Migrations from other databases follow a similar approach.
The migration process can be broken down into the following steps:
- Export databases from MySQL and MongoDB to JSON or CSV format.
- Create a Cloud Development environment.
- Create a new collection in the Cloud Development database.
- Import JSON or CSV format files in the collection.
Export
Export MySQL Data
In the following process, we use Navicat for MySQL to export data. You can also use other MySQL export tools.
Export to CSV Format
Select the table and export it.

Choose csv format from the type options.

Note: In step 4, we need to check the option to include column headers.

The exported csv file contains the key names in the first line, with each subsequent line representing key-value records corresponding to the header. As shown below:

Export to JSON Format
Similarly, we export the selected table to json format:

Export
What does the exported data look like?

After removing the array, is this the final result?

Export MongoDB Data
Start the mongod service first:

Do not close this terminal after startup.
Export to CSV Format
Open a new terminal and enter the following command:
mongoexport -db <database> --collection <collection name> --type csv -f <field name1[,field name2]> -o <output file path>
For more detailed parameter descriptions, please refer to the MongoDB documentation.
Note: When exporting to csv format, the field names must be specified; otherwise, an error will occur:
csv mode requires a field list
The exported data looks like:

Export to JSON Format
Open a new terminal and enter the following command:
mongoexport -db <database> --collection <collection name> -o <output file path>
For more detailed parameter descriptions, please refer to the MongoDB documentation.
The exported data looks like:

Import
Create a New Cloud Environment
If you already have a cloud environment, you can skip this step and directly open the Cloud Development Console to create a new cloud environment:

After creating a new environment, please wait patiently for the 2-minute environment initialization process.
Database Import
Click Add Collection to create a collection:

After creating, click to access and perform the import operation:

Select the CSV or JSON format file we previously exported.
There are two conflict resolution modes: Insert and Upsert.
- Insert mode will always insert new records during import. The same file cannot contain duplicate _id fields or have _id fields that are the same as existing records in the database. If you want to ensure that existing data is not overwritten, you should use Insert mode.
- Upsert mode determines whether a record exists. If it exists, it updates the record; otherwise, it inserts a new record. If you want to avoid redundant or duplicate data, you should use Upsert mode. :::
Here we select the Upsert mode:

After the import process is completed, you can view the imported data in the database:
