Exporting Data for Import into Cloud SQL

This pages describes how to create a SQL dump file or CSV file that is usable by Google Cloud SQL. You can use these files to import your data into Cloud SQL or to create an external master for Cloud SQL replicas.

For more information about importing data into Google Cloud SQL, see Overview of Importing and Exporting Data.

Creating a SQL dump file

  • --databases You must use the --databases option to specify an explicit list of databases to import, and this list must not contain the mysql system database.
  • --hex-blob If your database contains any binary fields, you must use this flag to ensure that your binary fields are imported correctly.
  • --skip-triggers Triggers should not be included in the SQL dump file.
  • --set-gtid-purged=OFF GTID information must not be included in the SQL dump file, nor should binary logging be disabled by the SQL dump file.
  • --ignore-table If 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 --master-data=1 and --flush-privileges flags.

In addition, do not use the --routines option. Routines should not be included in the SQL dump file.

From a command line, run mysqldump:

Standard configs

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

Ext replication

When you create a dump file for use in an external master or external replica configuration, you must ensure that you list all databases that you have created. If the replica does not include a database present on the 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 (mysql, performance_schema, and information_schema).

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 mysqldump reference.

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 '\"' "

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud SQL for MySQL