Migrating Data to TaurusDB Using mysqldump
You can use mysqldump to migrate data to TaurusDB.
Constraints
- Database migration is performed offline. Before the migration, you must stop any applications using the source database.
- mysqldump must match the DB engine version.
Preparing for the Migration
- Prepare an ECS or a device that can access TaurusDB instances over the public network.
- To connect to an instance through an ECS, you must first create an ECS.
For details on how to create and log in to an ECS, see Purchasing an ECS in Custom Config Mode and How Do I Log In to My ECS?
- To connect to a TaurusDB instance over a public network, you must:
- Bind the EIP to the instance. For details, see Binding an EIP.
- Ensure that the local device can access the EIP that has been bound to the instance.
- To connect to an instance through an ECS, you must first create an ECS.
- Install a MySQL client on the prepared ECS or device that can access the TaurusDB instance.
- Install the MySQL client by following the instructions provided in How Can I Install a MySQL Client?
- Ensure that the MySQL client version is the same as or later than the version of TaurusDB. The MySQL database or client will provide mysqldump and mysql.
Exporting Data
Before migrating data from the source database to the TaurusDB instance, you need to export data from the source database first.
- Log in to the prepared ECS or device that can access the TaurusDB instance.
- Use mysqldump to export metadata into a SQL file.
MySQL databases are required for TaurusDB management. When exporting metadata, do not specify --all-databases, or the databases will be unavailable.
mysqldump --databases DB_NAME --single-transaction --order-by-primary --hex-blob --no-data --routines --events --set-gtid-purged=OFF -u DB_USER -p -h DB_ADDRESS -P DB_PORT |sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' -e 's/DEFINER[ ]*=.*FUNCTION/FUNCTION/' -e 's/DEFINER[ ]*=.*PROCEDURE/PROCEDURE/' -e 's/DEFINER[ ]*=.*TRIGGER/TRIGGER/' -e 's/DEFINER[ ]*=.*EVENT/EVENT/' > BACKUP_FILE
- DB_NAME name of the database to be migrated.
- DB_USER: database user.
- DB_ADDRESS: database address.
- DB_PORT: database port.
- BACKUP_FILE: name of the file to which data will be exported.
Enter the database password when prompted.
Example:
mysqldump --databases gaussdb --single-transaction --order-by-primary --hex-blob --no-data --routines --events --set-gtid-purged=OFF -u root -p -h 192.*.*.* -P 3306 |sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' -e 's/DEFINER[ ]*=.*FUNCTION/FUNCTION/' -e 's/DEFINER[ ]*=.*PROCEDURE/PROCEDURE/' -e 's/DEFINER[ ]*=.*TRIGGER/TRIGGER/' -e 's/DEFINER[ ]*=.*EVENT/EVENT/' > dump-defs.sql
Enter password:
After this command is executed, the dump-defs.sql file will be generated.
- Use mysqldump to export data into a SQL file.
mysqldump --databases DB_NAME --single-transaction --hex-blob --set-gtid-purged=OFF --no-create-info --skip-triggers -u DB_USER -p -h DB_ADDRESS -P DB_PORT -r BACKUP_FILE
For details on the parameters in the preceding command, see 2.
Enter the database password when prompted.
Example:
mysqldump --databases gaussdb --single-transaction --hex-blob --set-gtid-purged=OFF --no-create-info --skip-triggers -u root -p -h 192.*.*.* -P 3306 -r dump-data.sql
After this command is executed, the dump-data.sql file will be generated.
Importing Data
You can use a client to connect to the TaurusDB instance through an ECS or device that can access the TaurusDB instance and then import the exported SQL files into that instance.
If the source database calls triggers, stored procedures, functions, or events, you must set log_bin_trust_function_creators to ON for the destination database before importing data.
- Import metadata into the TaurusDB instance.
mysql -f -h DB_ADDRESS -P DB_PORT -u root -p < BACKUP_DIR/dump-defs.sql
- DB_ADDRESS: IP address of the TaurusDB instance.
- DB_PORT: port of the DB instance.
- BACKUP_DIR: directory where the dump-defs.sql file is stored.
Example:
mysql -f -h 172.*.*.* -P 3306 -u root -p < dump-defs.sql
Enter password:
- Import data into the TaurusDB instance.
mysql -f -h DB_ADDRESS -P DB_PORT -u root -p < BACKUP_DIR/dump-data.sql
- DB_ADDRESS: IP address of the TaurusDB instance.
- DB_PORT: port of the DB instance.
- BACKUP_DIR: directory where the dump-data.sql file is stored.
Example:
mysql -f -h 172.*.*.* -P 3306 -u root -p < dump-data.sql
Enter password:
- Use the MySQL tool to connect to the TaurusDB instance and view the results.
show databases;
In this example, the database named my_db has been imported.
+--------------------+ | Database | +--------------------+ | information_schema | | my_db | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot