Upload Google Cloud SQL backup to Bigquery

前端 未结 2 1339
春和景丽
春和景丽 2021-01-23 13:19

I have had troubles trying to move a Google Cloud SQL database to BigQuery. I have exported the database backup from Cloud SQL to Cloud Storage, but when trying to import this

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 13:48

    You can use BigQuery Cloud SQL federated query to copy Cloud SQL table into BigQuery. You can do it with one BigQuery SQL statement. For example, following SQL copy MySQL table sales_20191002 to BigQuery table demo.sales_20191002.

    INSERT
       demo.sales_20191002 (column1, column2 etc..)
    SELECT
       *
    FROM
       EXTERNAL_QUERY(
          "project.us.connection",
          "SELECT * FROM sales_20191002;");
    

    EXTERNAL_QUERY("connection", "foreign SQL") would execute the "foreign SQL" in the Cloud SQL database specified in "connection" and return result back to BigQuery. "foreign SQL" is the source database SQL dialect (MySQL or PostgreSQL).

    Before running above SQL query, you need to create a BigQuery connection which point to your Cloud SQL database.

    To copy the whole Cloud SQL database, you may want to write a script to iterate all tables and copy them in a loop.

提交回复
热议问题