GSP-306: Migrate a Mysql Database to Google Cloud Sql

GSP-306: Migrate a Mysql Database to Google Cloud Sql

Overview

 1export ZONE=us-central1-a
 2
 3gcloud sql instances create wordpress --tier=db-n1-standard-1 --activation-policy=ALWAYS --gce-zone $ZONE
 4
 5gcloud sql users set-password --host % root --instance wordpress --password Password1*
 6
 7export ADDRESS=<external IP of blog vm/32>
 8
 9gcloud sql instances patch wordpress --authorized-networks $ADDRESS --quiet
10
11gcloud compute ssh blog --zone=us-central1-a
12
13MYSQLIP=$(gcloud sql instances describe wordpress --format="value(ipAddresses.ipAddress)")
14
15mysql --host=$MYSQLIP \
16    --user=root --password
17
18CREATE DATABASE wordpress;
19CREATE USER 'blogadmin'@'%' IDENTIFIED BY 'Password1*';
20GRANT ALL PRIVILEGES ON wordpress.* TO 'blogadmin'@'%';
21FLUSH PRIVILEGES;
22
23exit
24
25sudo mysqldump -u root -pPassword1* wordpress > wordpress_backup.sql
26
27mysql --host=$MYSQLIP --user=root -pPassword1* --verbose wordpress < wordpress_backup.sql
28
29sudo service apache2 restart
30
31cd /var/www/html/wordpress
32
33sudo nano wp-config.php

Replace the localhost with SQL Instance IP Congratulations, you're all done with the lab 😄