Search code examples
google-cloud-sqlgcloud-cli

Is it possible to rename a Cloud SQL database using the gcloud CLI?


I would like to rename a Cloud SQL database using only the gcloud CLI. I can see that I can patch a database using the CLI. However it seems to only patch either the collation or the charset but not the database name itself. Do you know if there is a way to achieve it with the CLI ?

If not, I will use a Cloud SQL Auth Proxy and run the ALTER command directly on the database.


Solution

  • I don't think, there is an in-built option to rename database using gcloud command-line.

    Available option is login to database engine and alter database name using ALTER DATABASE command, if it supports in-place database alteration.

    Another option is use gcloud sql to export your database to sql file, make changes to your database name and import it back to Cloud SQL instance.

    If you are using Cloud SQL MySQL instance, you can use mysqldump to backup and restore with new database name or use rename table with new database name.