1. Setup 2 MySQL, one to be a master (with binlogs), the other to be a slave; / Initialize scripts/mysql_install_db --basedir=/data/ushastry/server/mysql-advanced-5.6.20 --datadir=/tmp/master scripts/mysql_install_db --basedir=/data/ushastry/server/mysql-advanced-5.6.20 --datadir=/tmp/slave / Bring up bin/mysqld --no-defaults --basedir=/data/ushastry/server/mysql-advanced-5.6.20 --datadir=/tmp/master --log_bin=master-bin --port=3306 --socket=/tmp/master.sock --server_id=1 --pid-file=/tmp/master/mysqld.pid --user=root & bin/mysqld --no-defaults --basedir=/data/ushastry/server/mysql-advanced-5.6.20 --datadir=/tmp/slave --relay-log=slave-bin --port=3307 --socket=/tmp/slave.sock --server_id=2 --pid-file=/tmp/slave/mysqld.pid --master-info-repository=TABLE --relay-log-info-repository=TABLE --user=root & / Setup replication // master mysql> CREATE USER 'repl'@'localhost' IDENTIFIED BY 'slavepass'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> mysql> CREATE USER 'repl'@'127.0.0.1' IDENTIFIED BY 'slavepass'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'127.0.0.1'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +-------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------------+----------+--------------+------------------+-------------------+ | master-bin.000001 | 813 | | | | +-------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) // slave - captured ls from slave's dir BEFORE/AFTER CHANGE... [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110612 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:22 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:22 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema drwx------ 2 root root 4096 Sep 21 02:20 test mysql> CHANGE MASTER TO -> MASTER_HOST='127.0.0.1', -> MASTER_PORT=3306, -> MASTER_USER='repl', -> MASTER_PASSWORD='slavepass', -> MASTER_LOG_FILE='master-bin.000001', -> MASTER_LOG_POS=813; Query OK, 0 rows affected, 2 warnings (0.05 sec) [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110620 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:25 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:25 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 120 Sep 21 02:25 slave-bin.000001 -rw-rw---- 1 root root 19 Sep 21 02:25 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test mysql> START SLAVE; Query OK, 0 rows affected (0.01 sec) [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110624 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:27 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:27 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 167 Sep 21 02:27 slave-bin.000001 -rw-rw---- 1 root root 284 Sep 21 02:27 slave-bin.000002 -rw-rw---- 1 root root 38 Sep 21 02:27 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test 2. On the slave: "STOP SLAVE; DROP DATABASE IF EXISTS test_jfg; RESET SLAVE ALL;"; mysql> STOP SLAVE; DROP DATABASE IF EXISTS test_jfg; RESET SLAVE ALL; Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected (0.02 sec) [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110620 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:29 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:29 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 143 Sep 21 02:29 slave-bin.000001 -rw-rw---- 1 root root 19 Sep 21 02:29 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test 3. On the master: "DROP DATABASE IF EXISTS test_jfg; RESET MASTER;"; mysql> DROP DATABASE IF EXISTS test_jfg; RESET MASTER; Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected (0.01 sec) mysql> show master status; +-------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +-------------------+----------+--------------+------------------+-------------------+ | master-bin.000001 | 120 | | | | +-------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) 4. On the master: "CREATE DATABASE test_jfg;"; mysql> CREATE DATABASE test_jfg; Query OK, 1 row affected (0.00 sec) 5. On the slave: "CHANGE MASTER TO MASTER_HOST='', MASTER_USER='', MASTER_PASSWORD=''; START SLAVE IO_THREAD;"; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='slavepass'; [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110620 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:31 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:31 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 120 Sep 21 02:31 slave-bin.000001 -rw-rw---- 1 root root 19 Sep 21 02:31 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test START SLAVE IO_THREAD; [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110624 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:31 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:31 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:22 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 167 Sep 21 02:31 slave-bin.000001 -rw-rw---- 1 root root 390 Sep 21 02:31 slave-bin.000002 -rw-rw---- 1 root root 38 Sep 21 02:31 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test [root@cluster-repo mysql-advanced-5.6.20]# bin/mysqlbinlog --base64-output=decode-rows /tmp/slave/slave-bin.000002 .. .. # at 284 #140921 2:30:35 server id 1 end_log_pos 226 CRC32 0x4b4f7b26 Query thread_id=586 exec_time=0 error_code=0 SET TIMESTAMP=1411246835/*!*/; SET @@session.pseudo_thread_id=586/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1073741824/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; CREATE DATABASE test_jfg /*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; ^^ slave-bin.000002 contains CREATE DATABASE test 6. On the slave: "pkill -9 mysqld"; 7. On the slave: start mysqld with relay_log_recovery = 1. bin/mysqld --no-defaults --basedir=/data/ushastry/server/mysql-advanced-5.6.20 --datadir=/tmp/slave --relay-log=slave-bin --port=3307 --socket=/tmp/slave.sock --server_id=2 --pid-file=/tmp/slave/mysqld.pid --master-info-repository=TABLE --relay-log-info-repository=TABLE --relay_log_recovery=1 --skip_slave_start=1 --user=root & mysql> show slave status\G *************************** 1. row *************************** Relay_Log_File: slave-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Exec_Master_Log_Pos: 0 .. 1 row in set (0.00 sec) [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110628 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:34 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:34 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:34 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 167 Sep 21 02:31 slave-bin.000001 -rw-rw---- 1 root root 390 Sep 21 02:31 slave-bin.000002 -rw-rw---- 1 root root 120 Sep 21 02:34 slave-bin.000003 -rw-rw---- 1 root root 57 Sep 21 02:34 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test START SLAVE IO_THREAD; [root@cluster-repo mysql-advanced-5.6.20]# ls -l /tmp/slave total 110632 -rw-rw---- 1 root root 56 Sep 21 02:22 auto.cnf -rw-rw---- 1 root root 12582912 Sep 21 02:34 ibdata1 -rw-rw---- 1 root root 50331648 Sep 21 02:34 ib_logfile0 -rw-rw---- 1 root root 50331648 Sep 21 02:20 ib_logfile1 drwx------ 2 root root 4096 Sep 21 02:20 mysql -rw-rw---- 1 root root 6 Sep 21 02:34 mysqld.pid drwx------ 2 root root 4096 Sep 21 02:20 performance_schema -rw-rw---- 1 root root 167 Sep 21 02:31 slave-bin.000001 -rw-rw---- 1 root root 390 Sep 21 02:31 slave-bin.000002 <---------- CREATE DATABASE -rw-rw---- 1 root root 167 Sep 21 02:36 slave-bin.000003 -rw-rw---- 1 root root 390 Sep 21 02:36 slave-bin.000004 <---------- CREATE DATABASE -rw-rw---- 1 root root 76 Sep 21 02:36 slave-bin.index drwx------ 2 root root 4096 Sep 21 02:20 test [root@cluster-repo mysql-advanced-5.6.20]# bin/mysqlbinlog --base64-output=decode-rows /tmp/slave/slave-bin.000002 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #140921 2:31:53 server id 2 end_log_pos 120 CRC32 0x1c9d3b1f Start: binlog v 4, server v 5.6.20-enterprise-commercial-advanced created 140921 2:31:53 # at 120 #700101 5:30:00 server id 1 end_log_pos 0 CRC32 0x8ef1a9b8 Rotate to master-bin.000001 pos: 4 # at 168 #140921 2:30:07 server id 1 end_log_pos 120 CRC32 0xa826042e Start: binlog v 4, server v 5.6.20-enterprise-commercial-advanced-log created 140921 2:30:07 at startup ROLLBACK/*!*/; # at 284 #140921 2:30:35 server id 1 end_log_pos 226 CRC32 0x4b4f7b26 Query thread_id=586 exec_time=0 error_code=0 SET TIMESTAMP=1411246835/*!*/; SET @@session.pseudo_thread_id=586/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1073741824/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; CREATE DATABASE test_jfg /*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; [root@cluster-repo mysql-advanced-5.6.20]# bin/mysqlbinlog --base64-output=decode-rows /tmp/slave/slave-bin.000003 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #140921 2:34:16 server id 2 end_log_pos 120 CRC32 0xcf5b6c05 Start: binlog v 4, server v 5.6.20-enterprise-commercial-advanced created 140921 2:34:16 # at 120 #140921 2:36:06 server id 2 end_log_pos 167 CRC32 0x4f831059 Rotate to slave-bin.000004 pos: 4 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; [root@cluster-repo mysql-advanced-5.6.20]# bin/mysqlbinlog --base64-output=decode-rows /tmp/slave/slave-bin.000004 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #140921 2:36:06 server id 2 end_log_pos 120 CRC32 0x62da330f Start: binlog v 4, server v 5.6.20-enterprise-commercial-advanced created 140921 2:36:06 # at 120 #700101 5:30:00 server id 1 end_log_pos 0 CRC32 0x8ef1a9b8 Rotate to master-bin.000001 pos: 4 # at 168 #140921 2:30:07 server id 1 end_log_pos 120 CRC32 0xa826042e Start: binlog v 4, server v 5.6.20-enterprise-commercial-advanced-log created 140921 2:30:07 at startup ROLLBACK/*!*/; # at 284 #140921 2:30:35 server id 1 end_log_pos 226 CRC32 0x4b4f7b26 Query thread_id=586 exec_time=0 error_code=0 SET TIMESTAMP=1411246835/*!*/; SET @@session.pseudo_thread_id=586/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1073741824/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8 *//*!*/; SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; CREATE DATABASE test_jfg /*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 127.0.0.1 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 226 Relay_Log_File: slave-bin.000004 Relay_Log_Pos: 284 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1007 Last_Error: Error 'Can't create database 'test_jfg'; database exists' on query. Default database: 'test_jfg'. Query: 'CREATE DATABASE test_jfg' Skip_Counter: 0 Exec_Master_Log_Pos: 120 Relay_Log_Space: 557 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 1007 Last_SQL_Error: Error 'Can't create database 'test_jfg'; database exists' on query. Default database: 'test_jfg'. Query: 'CREATE DATABASE test_jfg' Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: bd5c7924-4107-11e4-b03e-00163e44510c Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: 140921 02:37:59 Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)