This tutorial is for you that is trying to import your current database into a Google Cloud SQL instance, replica
, that will be setup for replication purposes.
According to the documentation, you will need to run:
mysqldump \ -h [MASTER_IP] -P [MASTER_PORT] -u [USERNAME] -p \ --databases [DBS] \ --hex-blob --skip-triggers --master-data=1 \ --order-by-primary --compact --no-autocommit \ --default-character-set=utf8 --ignore-table [VIEW] \ --single-transaction --set-gtid-purged=on | gzip | \ gsutil cp - gs://[BUCKET]/[PATH_TO_DUMP]
The mysqldump
parameters are:
-h
the hostname or IPV4 address of theprimary
should replace[MASTER_IP]
-P
the port or theprimary
server, usually[MASTER_PORT]
value will be3306
-u
takes the username passed on[USERNAME]
-p
informs that a password will be given--databases
a comma separated list of the databases to be imported. Keep in mind[DBS]
should not include thesys
,performance_schema
,information_schema
, andmysql
schemas--hex-blob
necessary for dumping binary columns which types could beBINARY
,BLOB
and others--skip-triggers
recommended for the initial load, you can import the triggers at a later moment--master-data
according to the documentation: “It causes the dump output to include aCHANGE MASTER TO
statement that indicates the binary log coordinates (file name and position) of the dumped server”--order-by-primary
it dumps the data in the primary key order--compact
produces a more compact output, enabling several flags for the dump--no-autocommit
encloses the table between aSET autocommit=0
andCOMMIT
statements--default-character-set
informs the default character set--ignore-table
must list theVIEW
to be ignored on import, for multiple views, use this option multiple times. Views can be imported later on after promotion of the replica is done--single-transaction
aSTART TRANSACTION
is sent to the database so the dump will contain the data up to that point in time--set-gtid-purged
writes the the state of the GTID information into the dump file and disables binary logging when the dump is loaded into thereplica
After that the result is compressed in a GZIP file and uploaded to a bucket on Google Cloud Storage with gsutil cp - gs://[BUCKET]/[PATH_TO_DUMP]
where [BUCKET]
is the bucket you created on GCS and [PATH_TO_DUMP]
will save the file in the desired path.
Be aware that no DDL operations should be performed in the database while the dump is being generated else you might find inconsistencies.
See something wrong in this tutorial? Please don’t hesitate to message me through the comments or the contact page.