mysqldump 快速搭建特定庫主從架構(GTID)

對于數據總量不大的MySQL數據庫搭建主從架構,借助mysqldump工具來實現是不錯的選擇,再結合MySQL GTID特性,使得高可用輕而易舉。本文是基于mysqldump搭建gtid主從的補充。主要是介紹基于多庫級別實現GTID主從,即非整個實例級別。下面是本文的具體描述及示例。

相關知識點參考
基于mysqldump搭建gtid主從
MySQL GTID 錯誤處理匯總
配置MySQL GTID 主從復制
使用mysqldump導出數據庫

一、mysqldump時GTID參數

#?mysqldump?--help|grep?gtid-purged?-A8  ??--set-gtid-purged[=name]?  ??????????????????????Add?'SET?@@GLOBAL.GTID_PURGED'?to?the?output.?Possible  ??????????????????????values?for?this?option?are?ON,?OFF?and?AUTO.?If?ON?is  ??????????????????????used?and?GTIDs?are?not?enabled?on?the?server,?an?error?is  ??????????????????????generated.?If?OFF?is?used,?this?option?does?nothing.?If  ??????????????????????AUTO?is?used?and?GTIDs?are?enabled?on?the?server,?'SET  ??????????????????????@@GLOBAL.GTID_PURGED'?is?added?to?the?output.?If?GTIDs  ??????????????????????are?disabled,?AUTO?does?nothing.?If?no?value?is?supplied??????????????????????then?the?default?(AUTO)?value?will?be?considered.  ????????這個參數用于控制在導出數據庫時是否導出GTID,針對已開啟GTID的mysql實例??????????????????????  ????????就是說導出的數據中已經包含了這些GTID,因此在從庫開啟從之后需要被跳過  ????????缺省值為AUTO,如果導出時指定為OFF,則在從庫開啟從之后會收到error?1236

二、主從環境配置

????????主服務器:192.168.1.233:3306??server_id?:?233  ????????從服務器:192.168.1.245:3306??server_id?:?245--在主庫端創建復制用戶  ????????(root@Master)[(none)]>?GRANT?REPLICATION?SLAVE,?REPLICATION?CLIENT?ON?*.*?TO?'repl'@'%'?IDENTIFIED?BY?'123456';?    --?查看主庫端的配置文件  ????????(root@Master)[(none)]>system?grep?-v?^#?/etc/my.cnf    ????????[mysqld]    ????????sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES    ????????basedir?=?/usr/local/mysql  ????????datadir?=?/data    ????????server_id=233????????????????  ????????gtid_mode=on?????????????????  ????????enforce_gtid_consistency=on??    ????????log_bin=node233-binlog????????log-slave-updates=1????  ????????binlog_format=row??????????????  ????????report_host=Master???  ????????report_port=3306  ????????master-info-repository?=?TABLE  ????????relay-log-info-repository?=?TABLE  ????????replicate-do-db=tempdb  ????????replicate-do-db=testdb    ????????skip_slave_start=1????###該參數在啟動DB時不會自啟動slave,需要手動啟動??--?查看從庫端的配置文件?  ????????(root@Slave)[(none)]>system?grep?-v?^#?/etc/my.cnf    ????????[mysqld]    ????????basedir?=?/usr/local/mysql?  ????????datadir?=?/data??    ????????sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES    ????????server_id=245????????????????  ????????gtid_mode=on?????????????????  ????????enforce_gtid_consistency=on??    ????????log_bin=node245-binlog????????log-slave-updates=1????  ????????binlog_format=row????????????  ????????report_host=Slave  ????????report_port=3306  ????????master-info-repository?=?TABLE  ????????relay-log-info-repository?=?TABLE  ????????replicate-do-db=tempdb  ????????replicate-do-db=testdb    ????????skip_slave_start=1??###該參數在啟動DB時不會自啟動slave,需要手動啟動

三、主庫端的設置

演示環境  ????????(root@Master)[(none)]>show?variables?like?'version';  ????????+---------------+------------+  ????????|?Variable_name?|?Value??????|  ????????+---------------+------------+  ????????|?version???????|?5.7.12-log?|  ????????+---------------+------------+    --創建需要復制的數據庫tempdb與testdb????????(root@Master)[(none)]>create?database?tempdb;    ????????(root@Master)[(none)]>use?tempdb;    ????????(root@Master)[tempdb]>create?table?tb(`userId`?int);    ????????(root@Master)[(none)]>create?database?testdb;    ????????(root@Master)[(none)]>use?testdb;    ????????(root@Master)[testdb]>create?table?tb(`userId`?int);    --主庫端執行sql,使用如下腳本????????#?more?insert_id.sh?  ????????#/bin/sh  ????????cnt=1    ????????while?[?$cnt?-le?10000?]  ????????do  ????????????????mysql?-uroot?-ppass?-e?"insert?into?tempdb.tb(userId)?values($cnt);  ????????????????????????????????????????insert?into?testdb.tb(userId)?values($cnt)"  ????????????????let?cnt=$cnt+1  ???????????????????sleep?1?  ????????????????echo?"Insert?$cnt"  ????????done    --執行腳本????????#?./insert_id.sh?  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?2  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?3  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?4  ?????????????...........    --dump導出庫文件?????  ????????#?mysqldump?--single-transaction?--triggers?--routines?--events?--user=root?--password=pass?  ????????>?--databases?tempdb?testdb??>/tmp/multidb.sql??    --dump文件的內容????????#?more?/tmp/multidb.sql  ????????--?MySQL?dump?10.13??Distrib?5.7.12,?for?linux-glibc2.5?(x86_64)????????--????????--?Host:?localhost????Database:?tempdb????????--?------------------------------------------------------????????--?Server?version???????5.7.12-log????????--?非重要的信息省略?    ????????SET?@MYSQLDUMP_TEMP_LOG_BIN?=?@@SESSION.SQL_LOG_BIN;  ????????SET?@@SESSION.SQL_LOG_BIN=?0;    ????????--????????--?GTID?state?at?the?beginning?of?the?backup????????--  ????????--GTID信息,重要,用于主從復制跳過)????????SET?@@GLOBAL.GTID_PURGED='1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2318';    ????????--????????--?Current?Database:?`tempdb`????????--  ????????CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`tempdb`?/*!40100?DEFAULT?CHARACTER?SET?latin1?*/;    ????????USE?`tempdb`;    ????????--????????--?Table?structure?for?table?`tb`????????--  ????????DROP?TABLE?IF?EXISTS?`tb`;????????/*!40101?SET?@saved_cs_client?????=?@@character_set_client?*/;????????/*!40101?SET?character_set_client?=?utf8?*/;  ????????CREATE?TABLE?`tb`?(  ??????????`userId`?int(11)?DEFAULT?NULL  ????????)?ENGINE=InnoDB?DEFAULT?CHARSET=latin1;????????/*!40101?SET?character_set_client?=?@saved_cs_client?*/;    ????????--????????--?Dumping?data?for?table?`tb`????????--  ????????LOCK?TABLES?`tb`?WRITE;????????/*!40000?ALTER?TABLE?`tb`?DISABLE?KEYS?*/;  ????????INSERT?INTO?`tb`?VALUES?(1),(2),(3),(4),(5);????????/*!40000?ALTER?TABLE?`tb`?ENABLE?KEYS?*/;  ????????UNLOCK?TABLES;    ????????--????????--?Dumping?events?for?database?'tempdb'????????--  ????????--????????--?Dumping?routines?for?database?'tempdb'????????--  ????????--????????--?Current?Database:?`testdb`????????--  ????????CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`testdb`?/*!40100?DEFAULT?CHARACTER?SET?latin1?*/;    ????????USE?`testdb`;    ????????--????????--?Table?structure?for?table?`tb`????????--  ????????DROP?TABLE?IF?EXISTS?`tb`;????????/*!40101?SET?@saved_cs_client?????=?@@character_set_client?*/;????????/*!40101?SET?character_set_client?=?utf8?*/;  ????????CREATE?TABLE?`tb`?(  ??????????`userId`?int(11)?DEFAULT?NULL  ????????)?ENGINE=InnoDB?DEFAULT?CHARSET=latin1;????????/*!40101?SET?character_set_client?=?@saved_cs_client?*/;    ????????--????????--?Dumping?data?for?table?`tb`????????--  ????????LOCK?TABLES?`tb`?WRITE;????????/*!40000?ALTER?TABLE?`tb`?DISABLE?KEYS?*/;  ????????INSERT?INTO?`tb`?VALUES?(1),(2),(3),(4),(5);????????/*!40000?ALTER?TABLE?`tb`?ENABLE?KEYS?*/;  ????????UNLOCK?TABLES;    ????????--????????--?Dumping?events?for?database?'testdb'????????--  ????????--?在上面dump出來的每個表中可以看到導出的時候已經產生了數據1-5????????--?Dumping?routines?for?database?'testdb'????????--????????SET?@@SESSION.SQL_LOG_BIN?=?@MYSQLDUMP_TEMP_LOG_BIN;    --將導出文件復制到從服務器????????[root@node233?~]#?scp?/tmp/multidb.sql?192.168.1.245:/tmp

四、從庫端的設置

(root@Slave)[(none)]>reset?master;  ????????Query?OK,?0?rows?affected?(0.02?sec)    ????????(root@Slave)[(none)]>reset?slave?all;  ????????Query?OK,?0?rows?affected?(0.04?sec)    ????????(root@Slave)[(none)]>source?/tmp/multidb.sql    ????????(root@Slave)[tempdb]>CHANGE?MASTER?TO??  ????????????->?MASTER_HOST='192.168.1.233',????  ????????????->?MASTER_USER='repl',????  ????????????->?MASTER_PASSWORD='123456',????  ????????????->?MASTER_PORT=3306,????  ????????????->?MASTER_AUTO_POSITION?=?1;  ????????Query?OK,?0?rows?affected,?2?warnings?(0.07?sec)    ????????(root@Slave)[tempdb]>start?slave;  ????????Query?OK,?0?rows?affected?(0.05?sec)    ????????(root@Slave)[testdb]>show?slave?statusG????????***************************?1.?row?***************************  ???????????????????????Slave_IO_State:?Waiting?for?master?to?send?event  ??????????????????????????Master_Host:?Master  ??????????????????????????Master_User:?repl  ??????????????????????????Master_Port:?3306  ????????????????????????Connect_Retry:?60  ??????????????????????Master_Log_File:?node233-binlog.000008  ??????????????????Read_Master_Log_Pos:?201141  ???????????????????????Relay_Log_File:?node245-relay-bin.000002  ????????????????????????Relay_Log_Pos:?96813  ????????????????Relay_Master_Log_File:?node233-binlog.000008  ?????????????????????Slave_IO_Running:?Yes  ????????????????????Slave_SQL_Running:?Yes  ??????????????????????Replicate_Do_DB:?tempdb,testdb  ??????????????????Replicate_Ignore_DB:?  ???????????????????Replicate_Do_Table:?  ???????????????Replicate_Ignore_Table:?  ??????????????Replicate_Wild_Do_Table:?  ??????????Replicate_Wild_Ignore_Table:?  ???????????????????????????Last_Errno:?0  ???????????????????????????Last_Error:?  ?????????????????????????Skip_Counter:?0  ??????????????????Exec_Master_Log_Pos:?201141  ??????????????????????Relay_Log_Space:?97062  ??????????????????????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:?0  ????????Master_SSL_Verify_Server_Cert:?No  ????????????????????????Last_IO_Errno:?0  ????????????????????????Last_IO_Error:?  ???????????????????????Last_SQL_Errno:?0  ???????????????????????Last_SQL_Error:?  ??????????Replicate_Ignore_Server_Ids:?  ?????????????????????Master_Server_Id:?233  ??????????????????????????Master_UUID:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d  ?????????????????????Master_Info_File:?mysql.slave_master_info  ????????????????????????????SQL_Delay:?0  ??????????????????SQL_Remaining_Delay:?NULL  ??????????????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates  ???????????????????Master_Retry_Count:?86400  ??????????????????????????Master_Bind:???--?Author?:?Leshami  ??????????????Last_IO_Error_timestamp:???--?Blog???:?http://blog.csdn.net/leshami  ?????????????Last_SQL_Error_Timestamp:?  ???????????????????????Master_SSL_Crl:?  ???????????????????Master_SSL_Crlpath:?  ???????????????????Retrieved_Gtid_Set:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:2319-2702  ????????????????????Executed_Gtid_Set:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2702  ????????????????????????Auto_Position:?1  ?????????????????Replicate_Rewrite_DB:?  ?????????????????????????Channel_Name:?  ???????????????????Master_TLS_Version:

五、驗證主從記錄

--以下查詢中可以看到,兩個數據庫的表中的記錄在不停的增加  ????????(root@Slave)[testdb]>select?count(*)?from?tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+??????????  ????????|??????206?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tempdb.tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????214?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????216?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tempdb.tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????218?|  ????????+----------+

mysqldump 快速搭建特定庫主從架構(GTID)

對于數據總量不大的MySQL數據庫搭建主從架構,借助mysqldump工具來實現是不錯的選擇,再結合MySQL GTID特性,使得高可用輕而易舉。本文是基于mysqldump搭建gtid主從的補充。主要是介紹基于多庫級別實現GTID主從,即非整個實例級別。下面是本文的具體描述及示例。

相關知識點參考
基于mysqldump搭建gtid主從
MySQL GTID 錯誤處理匯總
配置MySQL GTID 主從復制
使用mysqldump導出數據庫

一、mysqldump時GTID參數

#?mysqldump?--help|grep?gtid-purged?-A8  ??--set-gtid-purged[=name]?  ??????????????????????Add?'SET?@@GLOBAL.GTID_PURGED'?to?the?output.?Possible  ??????????????????????values?for?this?option?are?ON,?OFF?and?AUTO.?If?ON?is  ??????????????????????used?and?GTIDs?are?not?enabled?on?the?server,?an?error?is  ??????????????????????generated.?If?OFF?is?used,?this?option?does?nothing.?If  ??????????????????????AUTO?is?used?and?GTIDs?are?enabled?on?the?server,?'SET  ??????????????????????@@GLOBAL.GTID_PURGED'?is?added?to?the?output.?If?GTIDs  ??????????????????????are?disabled,?AUTO?does?nothing.?If?no?value?is?supplied??????????????????????then?the?default?(AUTO)?value?will?be?considered.  ????????這個參數用于控制在導出數據庫時是否導出GTID,針對已開啟GTID的mysql實例??????????????????????  ????????就是說導出的數據中已經包含了這些GTID,因此在從庫開啟從之后需要被跳過  ????????缺省值為AUTO,如果導出時指定為OFF,則在從庫開啟從之后會收到error?1236

二、主從環境配置

????????主服務器:192.168.1.233:3306??server_id?:?233  ????????從服務器:192.168.1.245:3306??server_id?:?245--在主庫端創建復制用戶  ????????(root@Master)[(none)]>?GRANT?REPLICATION?SLAVE,?REPLICATION?CLIENT?ON?*.*?TO?'repl'@'%'?IDENTIFIED?BY?'123456';?    --?查看主庫端的配置文件  ????????(root@Master)[(none)]>system?grep?-v?^#?/etc/my.cnf    ????????[mysqld]    ????????sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES    ????????basedir?=?/usr/local/mysql  ????????datadir?=?/data    ????????server_id=233????????????????  ????????gtid_mode=on?????????????????  ????????enforce_gtid_consistency=on??    ????????log_bin=node233-binlog????????log-slave-updates=1????  ????????binlog_format=row??????????????  ????????report_host=Master???  ????????report_port=3306  ????????master-info-repository?=?TABLE  ????????relay-log-info-repository?=?TABLE  ????????replicate-do-db=tempdb  ????????replicate-do-db=testdb    ????????skip_slave_start=1????###該參數在啟動DB時不會自啟動slave,需要手動啟動??--?查看從庫端的配置文件?  ????????(root@Slave)[(none)]>system?grep?-v?^#?/etc/my.cnf    ????????[mysqld]    ????????basedir?=?/usr/local/mysql?  ????????datadir?=?/data??    ????????sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES    ????????server_id=245????????????????  ????????gtid_mode=on?????????????????  ????????enforce_gtid_consistency=on??    ????????log_bin=node245-binlog????????log-slave-updates=1????  ????????binlog_format=row????????????  ????????report_host=Slave  ????????report_port=3306  ????????master-info-repository?=?TABLE  ????????relay-log-info-repository?=?TABLE  ????????replicate-do-db=tempdb  ????????replicate-do-db=testdb    ????????skip_slave_start=1??###該參數在啟動DB時不會自啟動slave,需要手動啟動

三、主庫端的設置

演示環境  ????????(root@Master)[(none)]>show?variables?like?'version';  ????????+---------------+------------+  ????????|?Variable_name?|?Value??????|  ????????+---------------+------------+  ????????|?version???????|?5.7.12-log?|  ????????+---------------+------------+    --創建需要復制的數據庫tempdb與testdb????????(root@Master)[(none)]>create?database?tempdb;    ????????(root@Master)[(none)]>use?tempdb;    ????????(root@Master)[tempdb]>create?table?tb(`userId`?int);    ????????(root@Master)[(none)]>create?database?testdb;    ????????(root@Master)[(none)]>use?testdb;    ????????(root@Master)[testdb]>create?table?tb(`userId`?int);    --主庫端執行sql,使用如下腳本????????#?more?insert_id.sh?  ????????#/bin/sh  ????????cnt=1    ????????while?[?$cnt?-le?10000?]  ????????do  ????????????????mysql?-uroot?-ppass?-e?"insert?into?tempdb.tb(userId)?values($cnt);  ????????????????????????????????????????insert?into?testdb.tb(userId)?values($cnt)"  ????????????????let?cnt=$cnt+1  ???????????????????sleep?1?  ????????????????echo?"Insert?$cnt"  ????????done    --執行腳本????????#?./insert_id.sh?  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?2  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?3  ????????mysql:?[Warning]?Using?a?password?on?the?command?line?interface?can?be?insecure.  ????????Insert?4  ?????????????...........    --dump導出庫文件?????  ????????#?mysqldump?--single-transaction?--triggers?--routines?--events?--user=root?--password=pass?  ????????>?--databases?tempdb?testdb??>/tmp/multidb.sql??    --dump文件的內容????????#?more?/tmp/multidb.sql  ????????--?MySQL?dump?10.13??Distrib?5.7.12,?for?linux-glibc2.5?(x86_64)????????--????????--?Host:?localhost????Database:?tempdb????????--?------------------------------------------------------????????--?Server?version???????5.7.12-log????????--?非重要的信息省略?    ????????SET?@MYSQLDUMP_TEMP_LOG_BIN?=?@@SESSION.SQL_LOG_BIN;  ????????SET?@@SESSION.SQL_LOG_BIN=?0;    ????????--????????--?GTID?state?at?the?beginning?of?the?backup????????--  ????????--GTID信息,重要,用于主從復制跳過)????????SET?@@GLOBAL.GTID_PURGED='1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2318';    ????????--????????--?Current?Database:?`tempdb`????????--  ????????CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`tempdb`?/*!40100?DEFAULT?CHARACTER?SET?latin1?*/;    ????????USE?`tempdb`;    ????????--????????--?Table?structure?for?table?`tb`????????--  ????????DROP?TABLE?IF?EXISTS?`tb`;????????/*!40101?SET?@saved_cs_client?????=?@@character_set_client?*/;????????/*!40101?SET?character_set_client?=?utf8?*/;  ????????CREATE?TABLE?`tb`?(  ??????????`userId`?int(11)?DEFAULT?NULL  ????????)?ENGINE=InnoDB?DEFAULT?CHARSET=latin1;????????/*!40101?SET?character_set_client?=?@saved_cs_client?*/;    ????????--????????--?Dumping?data?for?table?`tb`????????--  ????????LOCK?TABLES?`tb`?WRITE;????????/*!40000?ALTER?TABLE?`tb`?DISABLE?KEYS?*/;  ????????INSERT?INTO?`tb`?VALUES?(1),(2),(3),(4),(5);????????/*!40000?ALTER?TABLE?`tb`?ENABLE?KEYS?*/;  ????????UNLOCK?TABLES;    ????????--????????--?Dumping?events?for?database?'tempdb'????????--  ????????--????????--?Dumping?routines?for?database?'tempdb'????????--  ????????--????????--?Current?Database:?`testdb`????????--  ????????CREATE?DATABASE?/*!32312?IF?NOT?EXISTS*/?`testdb`?/*!40100?DEFAULT?CHARACTER?SET?latin1?*/;    ????????USE?`testdb`;    ????????--????????--?Table?structure?for?table?`tb`????????--  ????????DROP?TABLE?IF?EXISTS?`tb`;????????/*!40101?SET?@saved_cs_client?????=?@@character_set_client?*/;????????/*!40101?SET?character_set_client?=?utf8?*/;  ????????CREATE?TABLE?`tb`?(  ??????????`userId`?int(11)?DEFAULT?NULL  ????????)?ENGINE=InnoDB?DEFAULT?CHARSET=latin1;????????/*!40101?SET?character_set_client?=?@saved_cs_client?*/;    ????????--????????--?Dumping?data?for?table?`tb`????????--  ????????LOCK?TABLES?`tb`?WRITE;????????/*!40000?ALTER?TABLE?`tb`?DISABLE?KEYS?*/;  ????????INSERT?INTO?`tb`?VALUES?(1),(2),(3),(4),(5);????????/*!40000?ALTER?TABLE?`tb`?ENABLE?KEYS?*/;  ????????UNLOCK?TABLES;    ????????--????????--?Dumping?events?for?database?'testdb'????????--  ????????--?在上面dump出來的每個表中可以看到導出的時候已經產生了數據1-5????????--?Dumping?routines?for?database?'testdb'????????--????????SET?@@SESSION.SQL_LOG_BIN?=?@MYSQLDUMP_TEMP_LOG_BIN;    --將導出文件復制到從服務器????????[root@node233?~]#?scp?/tmp/multidb.sql?192.168.1.245:/tmp

四、從庫端的設置

(root@Slave)[(none)]>reset?master;  ????????Query?OK,?0?rows?affected?(0.02?sec)    ????????(root@Slave)[(none)]>reset?slave?all;  ????????Query?OK,?0?rows?affected?(0.04?sec)    ????????(root@Slave)[(none)]>source?/tmp/multidb.sql    ????????(root@Slave)[tempdb]>CHANGE?MASTER?TO??  ????????????->?MASTER_HOST='192.168.1.233',????  ????????????->?MASTER_USER='repl',????  ????????????->?MASTER_PASSWORD='123456',????  ????????????->?MASTER_PORT=3306,????  ????????????->?MASTER_AUTO_POSITION?=?1;  ????????Query?OK,?0?rows?affected,?2?warnings?(0.07?sec)    ????????(root@Slave)[tempdb]>start?slave;  ????????Query?OK,?0?rows?affected?(0.05?sec)    ????????(root@Slave)[testdb]>show?slave?statusG????????***************************?1.?row?***************************  ???????????????????????Slave_IO_State:?Waiting?for?master?to?send?event  ??????????????????????????Master_Host:?Master  ??????????????????????????Master_User:?repl  ??????????????????????????Master_Port:?3306  ????????????????????????Connect_Retry:?60  ??????????????????????Master_Log_File:?node233-binlog.000008  ??????????????????Read_Master_Log_Pos:?201141  ???????????????????????Relay_Log_File:?node245-relay-bin.000002  ????????????????????????Relay_Log_Pos:?96813  ????????????????Relay_Master_Log_File:?node233-binlog.000008  ?????????????????????Slave_IO_Running:?Yes  ????????????????????Slave_SQL_Running:?Yes  ??????????????????????Replicate_Do_DB:?tempdb,testdb  ??????????????????Replicate_Ignore_DB:?  ???????????????????Replicate_Do_Table:?  ???????????????Replicate_Ignore_Table:?  ??????????????Replicate_Wild_Do_Table:?  ??????????Replicate_Wild_Ignore_Table:?  ???????????????????????????Last_Errno:?0  ???????????????????????????Last_Error:?  ?????????????????????????Skip_Counter:?0  ??????????????????Exec_Master_Log_Pos:?201141  ??????????????????????Relay_Log_Space:?97062  ??????????????????????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:?0  ????????Master_SSL_Verify_Server_Cert:?No  ????????????????????????Last_IO_Errno:?0  ????????????????????????Last_IO_Error:?  ???????????????????????Last_SQL_Errno:?0  ???????????????????????Last_SQL_Error:?  ??????????Replicate_Ignore_Server_Ids:?  ?????????????????????Master_Server_Id:?233  ??????????????????????????Master_UUID:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d  ?????????????????????Master_Info_File:?mysql.slave_master_info  ????????????????????????????SQL_Delay:?0  ??????????????????SQL_Remaining_Delay:?NULL  ??????????????Slave_SQL_Running_State:?Slave?has?read?all?relay?log;?waiting?for?more?updates  ???????????????????Master_Retry_Count:?86400  ??????????????????????????Master_Bind:???--?Author?:?Leshami  ??????????????Last_IO_Error_Timestamp:???--?Blog???:?http://blog.csdn.net/leshami  ?????????????Last_SQL_Error_Timestamp:?  ???????????????????????Master_SSL_Crl:?  ???????????????????Master_SSL_Crlpath:?  ???????????????????Retrieved_Gtid_Set:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:2319-2702  ????????????????????Executed_Gtid_Set:?1b64c25d-8d2b-11e6-9ac0-000c29b82d0d:1-2702  ????????????????????????Auto_Position:?1  ?????????????????Replicate_Rewrite_DB:?  ?????????????????????????Channel_Name:?  ???????????????????Master_TLS_Version:

五、驗證主從記錄

--以下查詢中可以看到,兩個數據庫的表中的記錄在不停的增加  ????????(root@Slave)[testdb]>select?count(*)?from?tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+??????????  ????????|??????206?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tempdb.tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????214?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????216?|  ????????+----------+    ????????(root@Slave)[testdb]>select?count(*)?from?tempdb.tb;  ????????+----------+  ????????|?count(*)?|  ????????+----------+  ????????|??????218?|  ????????+----------+

mysqldump 快速搭建特定庫主從架構(GTID)

以上就是mysqldump 快速搭建特定庫主從架構(GTID)的內容,更多相關內容請關注PHP中文網(www.php.cn)!

? 版權聲明
THE END
喜歡就支持一下吧
點贊9 分享