Search code examples
google-cloud-platformgoogle-cloud-storagegoogle-cloud-sql

Import CSV file from Local to Google Cloud SQL


Following the documentation, I am trying to import a local CSV onto a MySQL db hosted on GCP. I am using the following console command:

LOAD DATA LOCAL INFILE "C:/Users/user1/gcp/Feb_Pull.csv" INTO TABLE actuals CHARACTER SET 'utf8mb4' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"';

I get a 'File not found' error. Notes:

  • I'm using a Windows machine
  • I've also tried the code below but that does not work as noted in this thread.
> LOAD DATA LOCAL INFILE
> "gs://[projectname].appspot.com/bucket/Feb_Pull.csv" INTO TABLE
> actuals CHARACTER SET 'utf8mb4' FIELDS TERMINATED BY ',' OPTIONALLY
> ENCLOSED BY '\"' ESCAPED BY '\"';

What am I doing incorrectly? Any guidance or example is appreciated - thanks!

Edit:

  • I'm running my console from Google Cloud Shell

Solution

  • When running the Google Cloud Console, local files can be accessed thru the "Launch Code Editor" in the top right. There you will see a file explorer to which you can upload files.

    This will be your "local" directory from where the LOAD DATA LOCAL INFILE pulls from.