For general best practices for importing data into Cloud SQL, see Best Practices for Importing and Exporting Data.
Creating a SQL dump file
mysqldump to create your SQL dump file with the following flags:
--databasesYou must use the
--databasesoption to specify an explicit list of databases to import, and this list must not contain the
--hex-blobIf your database contains any binary fields, you must use this flag to ensure that your binary fields are imported correctly.
--skip-triggersTriggers should not be included in the SQL dump file.
--set-gtid-purged=OFFGTID information must not be included in the SQL dump file, nor should binary logging be disabled by the SQL dump file. (Not required for MySQL 5.5 or external replication.)
--ignore-tableIf your databases include VIEWs, you must exclude them from the export by including a
--ignore-table [VIEW_NAME]flag for each view in the databases being exported.
If you are creating a dump file for use in an external master or external
replica configuration, you
must also use the
In addition, do not use the
--routines option. Routines should not be
included in the SQL dump file.
From a command line, run
mysqldump --databases [DATABASE_NAME] -h [INSTANCE_IP] -u [USERNAME] -p \ --hex-blob --skip-triggers --set-gtid-purged=OFF --ignore-table [VIEW_NAME1] [...] \ --default-character-set=utf8 > [SQL_FILE].sql
When you create a dump file for use in an external master
configuration, you must ensure that you list all databases that
you have created. If the replica does not include a database present
on the external master instance, writing to that database can cause
replication to stop. You cannot simply export all databases,
however, because your dump file cannot include the system databases
For external replicas, you can choose a subset of your databases to be replicated, but you still must select individual databases to avoid the exporting the system databases.
mysqldump --databases [DATABASE_NAME1, DATABASE_NAME2, ...] -h [INSTANCE_IP] -u [USERNAME] -p \ --master-data=1 --flush-privileges --hex-blob --skip-triggers --ignore-table [VIEW_NAME1] [...] \ --default-character-set=utf8 > [SQL_FILE].sql
For more information about
mysqldump, see the
Creating a CSV file
To create a CSV file from your local MySQL server:
mysql --host=[INSTANCE_IP] --user=[USER_NAME] --password [DATABASE] \ -e " SELECT * FROM [TABLE] INTO OUTFILE '[FILE_NAME]' CHARACTER SET 'utf8' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' "
- Learn more about importing and exporting data.
- Read the
MySQL documentation about the