LOADING
×

MySQL Master Slave Configuration on GCP Virtual Machine

Having the exposure of GCP master-slave replication configured in your development environment is useful if you need it for a scale-out solution in the production environment.

MySQL Master Slave Configuration on GCP Virtual Machine

MySQL replication is a process that enables data from one MySQL database server (the master) to be copied automatically to one or more MySQL database servers (the slaves). It is usually used to spread read access on multiple servers for scalability, although it can also be used for other purposes such as for failover, or analyzing data on the slave in order not to overload the master.


1. Create a master-instance in cloud sql

2. Create an external-instance in compute engine(ubuntu 16.04lts)

3. Install mysql server in external instance

  1. sudo apt-get update
  2. sudo apt-get install mysql-server
  3. mysql_secure_installation
  4. After installation check (mysql -u root -p:)





4. Now authorize the external instance to cloud sql master, add the IP of External instance


5. Now open cloud shell

a. gcloud sql connect master-instance --user=root



b. CREATE USER '[replication_user]'@'%'IDENTIFIED BY '[replication_password]';



c. CREATE USER '[replication_user]'@'%'IDENTIFIED BY '[replication_password]';




6. Now in ssh find my.cnf file

a. cd /etc/mysql

b. ls

c. sudo nano mysqld.cnf




d. sudo nano mysqld.cnf


7. Restart the mysqld process to cause the configuration file to be read

a. sudo systemctl restart mysql



8. Enter into the root directory (sudo -i) and run


a. service mysql status




9. Restart

a. systemctl restart mysql



10. Change master to

a.MASTER_HOST='[MASTER_IP_ADDRESS]',MASTER_USER='[REPLICATION_USER]',MASTER_PASSWORD='[REPLICATION_PASSWORD]',MASTER_AUTO_POSITION=1;


b. START SLAVE;

c. SHOW SLAVE STATUS\G;


11. If there is no error in the process then changes made in master is reflected in slave





Trendy