GaussDB(for MySQL) supports public accessibility. You can access GaussDB(for MySQL) through a private network or EIP.
For details on how to create and log in to an ECS, see descriptions about creating an ECS and logging in an ECS in the Elastic Cloud Server User Guide.
For details, see How Can I Install the MySQL Client?
The version of the GaussDB(for MySQL) client must be the same as or later than that of the GaussDB(for MySQL) server. The MySQL database or client provides the mysqldump and mysql tools by default.
Before migrating data to GaussDB(for MySQL), you need to export data first.
MySQL databases are required for GaussDB(for MySQL) management. When exporting metadata, do not specify --all-database. Otherwise, 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>
Enter the database password as 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.168.151.18 -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.
MySQL databases are required for GaussDB(for MySQL) management. When exporting metadata, do not specify --all-database. Otherwise, the databases will be unavailable.
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 as prompted.
Example:
mysqldump --databases gaussdb --single-transaction --hex-blob --set-gtid-purged=OFF --no-create-info --skip-triggers -u root -p -h 192.168.151.18 -P 3306 -r dump-data.sql
After this command is executed, the dump-data.sql file will be generated.
You can use a client to connect to a GaussDB(for MySQL) DB instance through an ECS or a device and then import the exported SQL file into that DB instance.
If the source database contains triggers, storage processes, functions, or event invocation, you must set log_bin_trust_function_creators to ON for the destination database before importing data.
Use the MySQL tool to connect to the GaussDB(for MySQL) DB instance, enter the password, and run the following command to import metadata:
mysql -f -h <DB_ADDRESS> -P <DB_PORT> -u root -p < <BACKUP_DIR>/dump-defs.sql
Example:
mysql -f -h 172.16.66.198 -P 3306 -u root -p < dump-defs.sql
Enter password:
mysql -f -h <DB_ADDRESS> -P <DB_PORT> -u root -p < <BACKUP_DIR>/dump-data.sql
Example:
mysql -f -h 172.16.66.198 -P 3306 -u root -p < dump-data.sql
Enter password:
mysql> show databases;
In this example, the database named my_db has been imported.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | my_db | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)