0
votes

Is there a way for me to import csv files to cloud sql? I've tried to follow this tutoriaL but I didn't work: https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/import#request-body

Is there any other way to accomplish this?

Thanks!

1

1 Answers

0
votes

If you provide some more information regarding the fail message we might be able to tell you what you need to fix in order to complete the tutorial. However, You can do something a little ugly, but it works. You'll need to import pymysql.

So lets assume that the CSV data is in csv_file_lines list variable. Now we need to go over the lines and execute an insert to the tables, with the current line's data, in the following way:

db = pymysql.connect(host=<host>,port=<port>,user=<user>,password=<password>)
cursor = db.cursor()
for line in csv_file_lines:
    cursor.execute('INSERT INTO TABLE....')