Clone Replication Slave From Live Master Using GTID and mysqldump

To clone a replication slave from a live master with existing data, ensure that you copy the data as a consistent snapshot and also ensure that correct GTID status is transferred to the slave.
Follow these steps:
  1. Create a data export using mysqldump and the following options on the
    master server
    . Copy the resulting <source_Gateway>.sql to the slave server using SCP or similar.
    # mysqldump ssg --set-gtid-purged=on --routines > /home/ssgconfig/<source_Gateway>.sql # scp /home/ssgconfig/<source_Gateway>.sql [email protected]<destination_Gateway_Hostname>:~/
  2. Ensure that replication is not running on the
    slave server
    :
    slave> STOP SLAVE; Query OK, 0 rows affected (0.02 sec)
    Note:
    Create SSG database if not already available.
  3. On the
    slave server,
    if GTIDs are enabled earlier and the existing value of gtid_executed is not empty, for example:
    slave> SELECT @@global.gtid_executed; +-------------------------------------------+ | @@global.gtid_executed | +-------------------------------------------+ | 3205efd7-86b0-11e6-9bb1-08002715584a:1-15 | +-------------------------------------------+ 1 row in set (0.00 sec)
    You must first execute a RESET MASTER
    on the slave
    :
    Ensure that you perform this step only
    on the slave
    .
  4. Use the MySQL client to import <source_Gateway>.sql on the
    slave server
    .
    # mysql ssg < /home/ssgconfig/<source_Gateway>.sql
  5. Verify that the global variables
    gtid_executed
    and
    gtid_purged
    have been set on the
    slave server.
    This is done inside of <source_Gateway>.sql as we used the --set-gtid-purged flag with mysqldump.
    slave> SELECT @@global.gtid_executed, @@global.gtid_purged; +-------------------------------------------+-------------------------------------------+ | @@global.gtid_executed | @@global.gtid_purged | +-------------------------------------------+-------------------------------------------+ | 3205efd7-86b0-11e6-9bb1-08002715584a:1-25 | 3205efd7-86b0-11e6-9bb1-08002715584a:1-25 | +-------------------------------------------+-------------------------------------------+ 1 row in set (0.00 sec)
  6. Configure replication with the master hostname, port, username, and password on the
    slave server
    . Then start the slave process.
    # /opt/SecureSpan/Appliance/bin/create_slave.sh
  7. Check the slave status on the
    slave server
    to ensure that the replication is operating correctly without any errors. The server quickly catches up to any changes made since the export started. Examine Seconds_Behind_Master to see if the slave server is up to date with all the changes.
    Check the results for Slave_IO_Running, Slave_SQL_Running, which should be
    Yes
    and check if the values of Last_IO_Error and Last_SQL_Error are blank.
    slave> SHOW SLAVE STATUS\G
Your replication slave is now ready for use.