Can I run an sql file on my Google Cloud Sql instance using the gcloud sql command
Asked Answered
C

2

7

I have an sql file that creates my mysql database and all my users and tables.

I am trying to figure out of there is a way I can automate using this sql file to initialize the database on my Google Cloud sql instance.

So far, the only way I have been able to determine, is that I use the gcloud sql connect command, and then just copy and paste the contents of the sql file into the mysql prompt.

There has got to be a better way though. Looking through the gcloud sql docs, I have not been able to find one. Am I missing something?

Compliancy answered 8/7, 2020 at 16:30 Comment(4)
Have you considered any MySQL client (e.g Workbench) to connect to the Cloud SQL and run the query file from your local machine?Habitual
No. I was hoping I could do it with scripts and not gui tools.Compliancy
I believe that there is nothing like this on the console, but you could try with the importing tool and exporting tool, as it runs with gcloud you could make a shell script with gcloud, but besides from that, I don't seem to find a faster way besides from what you did. import toolHesitant
as Daz mentioned Gcloud commands are meant to perform actions over the infrastructure serving your Mysql Database but whatever happens on your instance (on in your Mysql database) depends on you and need you to act directly over it since Google doesn't have access to whats inside your instanceIntercrop
A
4

gcloud sql is oriented towards managing the Cloud SQL instance.

Once you've created an instance, you may use any regular MySQL tool to interact with the instance including creating tables.

For example, see: https://cloud.google.com/sql/docs/mysql/connect-admin-proxy

I encourage you to use Google's Cloud SQL proxy to connect to the remote instance, see: https://cloud.google.com/sql/docs/mysql/quickstart-proxy-test

Astonishing answered 8/7, 2020 at 17:7 Comment(0)
A
0

Steps to run an sql file on my Google Cloud Sql instance using the gcloud sql console are as follows:

  1. Create a GCP storage bucket (ideally in the same project)
  2. Upload the file to this bucket
  3. Import the sql file from this bucket in the overview section of the GCP SQL console

There is a comprehensive set of instructions here: virginia uni GCP DB setup

Albinus answered 24/12, 2021 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.