Requirements for importing and exporting
CSV file format requirements
- CSV files must have one line for each row of data and have comma-separated fields.
- The format of CSV files that Cloud SQL accepts is equivalent to
using the MySQL statements
"LOAD DATA INFILE ... CHARACTER SET 'utf8' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"'.
When preparing a CSV for importing, make sure your select statement includes these statements. For more information, see the SELECT Syntax page in the MySQL documentation.
If you need to import a CSV file that is not in the correct format, you can
do so by using the
LOAD DATA LOCAL INFILE
statement in the
mysql client, which loads a local file to the database.
Best practices for importing and exporting
The following are best practices you should consider when importing and exporting data:
Use the correct flags when you create a SQL dump file
If you do not use the correct flags when you export your data to a SQL dump file, your import might not be successful. For information about creating a mysqldump file for import into Google Cloud SQL, see Creating a mysqldump file.
Compress data to reduce cost
Cloud SQL supports importing and exporting both
compressed and uncompressed
mysqldump files. Compression can save significant storage space on
Google Cloud Storage and reduce your storage costs, especially when you are
exporting large instances. When you export a SQL dump file, use a
extension to compress the data. When you import a dump file with
a file extension of
.gz, it is decompressed automatically.
Second Generation instances also support compression for CSV files. You cannot use compressed CSV files for First Generation instances.
InnoDB is the only supported storage engine for Second Generation instances. For First Generation instances, all storage engines are supported.
You can convert your tables from MyISAM to InnoDB by piping the output of mysqldump through a sed script as follows:
mysqldump --databases [DATABASE_NAME] \ -h [INSTANCE_IP] -u [USERNAME] -p [PASSWORD] \ --hex-blob --default-character-set=utf8 | sed 's/ENGINE=MyISAM/ENGINE=InnoDB/g' > [DATABASE_FILE].sql
For long-running import and export processes
Imports and exports into Google Cloud SQL using the import functionality (via a Cloud Storage bucket) can take a long time to complete, depending on the size of the database. This can have the following impacts:
- On First Generation instances, operations are limited to 24 hours.
- You cannot stop a long-running operation.
In addition, you can perform only one import or export operation at a time for each instance.
You can decrease the amount of time a single operation requires by using one of the following approaches:
Use the Cloud SQL import or export functionality, but do it with smaller batches of data that will take less than 24 hours to complete.
Don't use the Cloud SQL import or export functionality, but instead replay a dump file directly to Cloud SQL. For example, you can use
cloudsql-import, which imports by replaying a mysqldump file over a MySQL connection.
cloudsql-importis resilient to connection failures and instance restarts.
For more tips, see Diagnosing Issues with Cloud SQL Instances.