Importing Data Google Professional Data Engineer GCP
In this, we will learn the concept of importing data.
- To import data from Cloud Storage, the instance’s service account must have the legacyBucketReader Cloud IAM role set in the project.
- Import as SQL dump file or CSV for MySQL and PostgreSQL and for SQL Server option of BAK file is present
- Importing the SQL dump file / BAK file or CSV file to CloudSQL from console, as REST or use gcloud
- Import can be done by sql dump or csv.
- Sql dump cannot contain triggers, views, stored procedures.
Importing SQL dump files to Cloud SQL
- Do not use a system user (such as root@localhost) as the DEFINER for triggers, view, or stored procedures. You won’t have access to this user in Cloud SQL.
- The database you are importing into must already exist on Cloud SQL instance and it must be empty. You can’t overwrite existing data.
- The SQL Mode setting affects how Cloud SQL interprets SQL queries.
- Create a Cloud Storage bucket and upload the file to the bucket.
- Select the instance in the Cloud SQL Instances page in the Google Cloud Console.
- Click Import in the button bar.
- Enter the path to the bucket and SQL dump file
- For Format, select SQL.
- Select the database you want the data to be imported into.
Using gcloud Steps
- Create a Cloud Storage bucket, if you haven’t already.
- Upload the file to bucket.
- Describe the instance you are importing to: gcloud sql instances describe [INSTANCE_NAME]
- Copy the serviceAccountEmailAddress field.
- Use gsutil IAM to grant the legacyBucketWriter and objectViewer Cloud IAM roles to the service account for the bucket.
- Import the database: gcloud sql import sql [INSTANCE_NAME] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME] \
–database=[DATABASE_NAME]
- If the command returns an error like `ERROR_RDBMS`, review the permissions; this error is often due to permissions issues.
Google Professional Data Engineer (GCP) Free Practice TestTake a Quiz