How to use gcloud sql export and not add "CREATE DATABASE" and "USE" on the sql file
Asked Answered
A

1

6

I want to use the gcloud sql instance export command to export a database, to be imported to another database on the same server.

The problem is that using:

gcloud sql instances export instancename gs://bucket/dbname.sql.gz -d=dbname

adds the below to the top of the sql file:

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `dbname` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `dbname`;

Since I want to be able to import the sql file to another database with the gcloud sql instance import, the USE dbname makes the import go to the dbname database instead of other one.

So is there a way for me to export the database but don't add that to the file? I've searched the documentation of the command and didn't found anything related to that.

Angola answered 13/6, 2017 at 12:41 Comment(0)
D
4

Just manually edit the dump file, currently there is no existing functionality which would prepare an export according to your requirements.

Defibrillator answered 13/6, 2017 at 15:25 Comment(4)
Thanks, I was afraid that was the only option. Do you know if adding that in the future is in the pipeline? As I believe that is possible through mysqldump, and since this is to be used in an automated flow, would simplify the script by a bit (and in running time), specially if the file is big.Miscegenation
I'm not aware of any planned work in this area, but you're welcome to file a feature request here: issuetracker.google.com/issues/…Defibrillator
I've filed a Feature Request for this, since I couldn't find any: issuetracker.google.com/issues/116727095Vasilikivasilis
This is very bad and adds so much complexity for a simple task. Anyone has a script for this already?Cranny

© 2022 - 2024 — McMap. All rights reserved.