Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

How to create a gtid slave for an existing database?

$
0
0

There seem to be very few guides on setting up mysql replication for failover (and failback) for 5.6 using gtid. The official manual shows how to do it for an existing replicated setup, but not for a new setup. I have combined several sources to come up with the following steps, but I don't know:

  1. how (and at what point) to correctly seed the slaves,
  2. whether users/grants need to be done on both master and slaves,
  3. why I should use "skip-slave-start" in the config, and if I do, what happens if it becomes the master? etc.
  4. how to failover, and how to make old master a slave (especially as most articles hard code master/slave specific directives in the my.cnf)

I have found articles how to do it pre-gtid, but it is unclear how the steps for this translate into gtid world.

Phase 1 (pre-replication)

  1. Install mysql 5.6.19 (>19 has changes which break our app) on server a.
  2. create database "foo" on server a
  3. setup our application to use server a (via its ip) and generate a lot of data in foo.

Phase 2 setup slave

  1. install mysql 5.6.19 on server b.

Phase 3 copy master data to slave. Or should this be phase 4 or 5?.

  1. Do something???
  2. mysqldump mydb > mydb.sql
  3. do something on slave???
  4. restore mydb.sql to slave
  5. do something else on slave???

Phase 4 setup replication (MASTER)

  1. Presumably we should stop the application, and tell everyone to stop using db.
  2. edit my.cnf

add:

log-bin = mysql-bin
server-id = 1
binlog_format = MIXED   ## or ROW?
enforce-gtid-consistency
gtid-mode=ON
binlog_do_db = foo  ## dont know if this is needed?
log-slave-updates     ## dont know if this is needed?
relay-log-recovery    ## dont know if this is needed?
  1. service mysql restart
  2. setup rep user on master:

mysql -u root -p

create user 'replicator'@'%' identified by 'xxx'; 
grant replication slave on *.* to 'replicator'@'%'; 

Phase 5 setup SLAVE

  1. edit my.cnf:

Add:

  server_id = 2
log_bin = mysql-bin
binlog_format = MIXED  ## or ROW?
skip_slave_start            ## is this needed?  What if this server becomes master???
gtid_mode = on
enforce_gtid_consistency
log_slave_updates
binlog_do_db = foo  ## dont know if this is needed?
  1. create users? Do we need to do the same create user and grant as for the master? What if this slave becomes the master?
  2. service mysql restart

Phase 6 start replication

On slave only?

SQL> CHANGE MASTER TO
 MASTER_HOST='master_ip',
 MASTER_PORT=3306,
 MASTER_USER='slave_user_name',
 MASTER_PASSWORD='xxx',
 MASTER_AUTO_POSITION=???;

SQL> START SLAVE;

Phase 7, master dies make slave new master

  1. ?
  2. Stop our application servers, manually change the IP to the slave. Is there a better way?
  3. start our application servers.

Phase 8, master backup make it new slave

  1. ?

Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>