0

On Cloud SQL, with MySQL engine, how can I replace the functionality LOAD DATA INFILE ... REPLACE?

We are migrating our web platform to Google Cloud using App Engine and Cloud SQL.

We use LOAD DATA INFILE with either the mode IGNORE or REPLACE, to import CSV files into our tables.

Since the instruction LOAD DATA INFILE is not supported on Cloud SQL, how can we manage to replace it?

I have tried to use gcloud sql import csv and Cloud SQL API but it seems the option to IGNORE or REPLACE duplicate data is not present.

To give an example, here is the table in which the data is imported:

C1 | C2 | C3 | C4
-----------------
1  | 2  | 3  | A |
4  | 5  | 6  | B |
7  | 8  | 9  | C |

On this table there is a unique index on columns C1+C2+C3

Now I need to import a CSV file containing the following:

1,2,3,AA

If I used LOAD DATA INFILE with option REPLACE, the table after import would be like this:

C1 | C2 | C3 | C4
-----------------
1  | 2  | 3  | AA |
4  | 5  | 6  | B  |
7  | 8  | 9  | C  |

So, I would like to obtain the same behaviour on Cloud SQL with either gcloud sql import csv or Cloud SQL API.

We need to do this programmatically with PHP.

Is it possible or is there another possibility?

Thanks

Patulacci
  • 5
  • 5

1 Answers1

1

LOAD DATA LOCAL INFILE is supported by App Engine.

The answer to this question are in these links:

Importing Data to Google Cloud SQL via CSV

Google Cloud SQL: Alternative to LOAD DATA INFILE

  • Thank you for your answer, but I still don't understand how to transfer the file from the bucket to Cloud SQL instance and then use LOAD DATA LOCAL INFILE. I mean, could copy the file manually from my local computer to Cloud Shell but how to programmatically do it with PHP and from the bucket? – Patulacci May 17 '19 at 08:37
  • 1
    Ok, I have just understood how to do it. I copy the file from GCP bucket to App Engine and then I use LOAD DATA LOCAL INFILE to import it into the database. Thanks – Patulacci May 21 '19 at 09:47