1

I have two servers in different regions (eu, us) connected to the same mysql database, I've started with google cloud sql second generation but it's only available on us region.

The idea is to add a second sql nodes in the new region eu but I can't find any documentation about Master-Master replication so it is not supported at this time. Is this correct?

ps. both of my servers need read/write access.

With my operational google sql in us, can I just:

  1. I create a new google sql cloud in eu.

  2. Configure eu as an External Replicas for us.

  3. Configure eu as External Masters for us.

I'm really confused! Any help will be appreciated.

/Ouss

O.Hammami
  • 176
  • 1
  • 7
  • Google has SQL-ish replicated database called cloud-spanner – midor Nov 09 '17 at 23:15
  • I think I’ll do it using spanner, it’s not really cheap but let’s see and I will update this question with my feedback, thanks midor – O.Hammami Nov 11 '17 at 00:33
  • There's always the possibility to use a container or vm as a service, if you know how to do the setup – midor Nov 13 '17 at 04:39
  • I would be interested in how it went for you. Will you add feedback at some point? – midor Jan 23 '18 at 13:31
  • I've installed mysql server in a VM, then the master master replication as normal, no big deal. – O.Hammami Jan 24 '18 at 14:34
  • 1
    Thanks for the info. Ofc. that works; kind of defeats the purpose of using Cloud SQL in the first place. – midor Jan 24 '18 at 16:40

2 Answers2

1

Master-Master is not supported in Google Cloud SQL.

Vadim
  • 4,996
  • 1
  • 26
  • 30
rvs
  • 1,251
  • 13
  • 22
  • Yes I’ve noticed that but I’m asking about a workaround or an idea, have someone did it in a cloud ? Should I install my own mysql server a tke care of all and do it myself... – O.Hammami Nov 11 '17 at 00:30
  • I highly doubt there is a workaround. Even if there is, it would not be supported so may break any time. I recommend you to step back and think about what you are really trying to archieve. master-master in traditional SQL databases is not a magic bullet and have a lot of problems. If you really need multi-region consistent database, look at Spanner. – rvs Nov 11 '17 at 15:23
0

Solution from: https://www.ryadel.com/en/mysql-master-master-replication-setup-in-5-easy-steps/

Successfully implemented on Linux Ubuntu 16.04 in google cloud platform MySql 5.7 will not load on Debian.

/// Install MySQL on 2 VMs

A. On VMs sql1 & sql2

apt update
apt install mysql-server -y

P@ssW0rd2020    P@ssW0rd2020

B. Comment bind-address to allow global access

cd /etc/mysql/mysql.conf.d/

nano /etc/mysql/mysql.conf.d/mysqld.cnf

C. Restart MySQL Service (cnf changed)

systemctl restart mysql
systemctl status mysql

D. On sql1

nano /etc/mysql/conf.d/mysql.cnf

[mysqld]   // note: not [mysql]

server-id=1
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 1

-------------------------------------

systemctl restart mysql
systemctl status mysql

D. On sql2

nano /etc/mysql/conf.d/mysql.cnf

[mysqld]

server-id=2
log-bin="mysql-bin"
binlog-ignore-db=test
binlog-ignore-db=information_schema
replicate-ignore-db=test
replicate-ignore-db=information_schema
relay-log="mysql-relay-log"
auto-increment-increment = 2
auto-increment-offset = 2

-------------------------------------

systemctl restart mysql (THIS WILL CREATE BIN LOG)
systemctl status mysql

again, flush privileges; ---supposed to 

E. Create the Replicator User(s)

  • Configure on both sql1 & 2 (replicator password can be same for, or not)

    mysql -u root -p

    P@ssW0rd2020

    CREATE USER 'replicator'@'%' IDENTIFIED BY 'P@ssW0rd2020'; GRANT REPLICATION SLAVE ON . TO 'replicator'@'%' IDENTIFIED BY 'P@ssW0rd2020'; flush privileges;

F. Start with fresh VMs with no databases (better) or mutual import/export databases into sql1 & 2 https://dev.mysql.com/doc/refman/8.0/en/copying-databases.html

G. Configure replication from sql1 to sql2 (make sql2 slave of sql1)

  • On sql1

    SHOW MASTER STATUS;

    example output: +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 448 | example | test, informatio | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

    • NOTE 'file' and 'position' values
  • On sql2

    STOP SLAVE; CHANGE MASTER TO MASTER_HOST = '104.154.225.215', MASTER_USER = 'replicator', MASTER_PASSWORD = 'P@ssW0rd2020', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 448; START SLAVE; flush privileges;

H. Repeat for sql2 (make sql1 slave of sql2)

  • on sql2

    SHOW MASTER STATUS;

    example output: +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 448 | example | test, informatio | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

    • NOTE 'file' and 'position' values
  • On sql1

    STOP SLAVE; CHANGE MASTER TO MASTER_HOST = '35.198.195.130', MASTER_USER = 'replicator', MASTER_PASSWORD = 'P@ssW0rd2020', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 448; START SLAVE;

I. Test the Replication

  • Create a database on sql1 it will be replicated on sql2, vice versa.
  • Create a database on sql2 it will be replicated on sql1, vice versa.

SUCCESS IS SWEET!

James R
  • 1
  • 1