MySQL5.6ã®mysqlbinlogã³ãã³ã
MySQL5.6ããmysqlbinlogã³ãã³ãã«ãã¤ããªãã°ãããã¯ã¢ããããããã®ãªãã·ã§ã³ãå¤æ°è¿½å ããã¦ãã¾ãããã®ä¸ãããã¼ãããªãã·ã§ã³ã«ã¤ãã¦ã¾ã¨ãã¾ãããªããä¸åº¦ã¯公式ドキュメントãèªãäºããå§ããã¾ãã
åºæ¬çã«ãªãã·ã§ã³ã¯çç¥å½¢ã§è¨è¼ãã¦ãã¾ãããé©å®()ã§çç¥å½¢ãè¨è¼ãã¦ãã¾ãã
ãªã¢ã¼ãã®MySQLã®ãã¤ããªãã°ãã³ãã¼
ãªãã·ã§ã³ã«ããè²ã ãªã³ãã¼ã®ä»æ¹ãç¨æããã¦ãã¾ããåºæ¬çã«ã¯--read-from-remote-serverãªãã·ã§ã³(-R)ããã¼ã¹ã¨ãã¦ç¨éã«ãã追å ã§ãªãã·ã§ã³ãæå®ãã¾ãã
æ¥ç¶ãããMySQLããè¦ãã¨Slaveããã®æ¥ç¶ã¨å¤ãããªããããªã®ã§server_idããªãã·ã§ã³ã§æå®å¯è½ãªç©ãããã¾ããæå®ããªãå ´åã¯ä½¿ç¨ãããªãã·ã§ã³ã«ãã0ãã¾ãã¯65535ãããã©ã«ãã§ä½¿ç¨ããã¾ããæ¡ä»¶ã«ã¤ãã¦ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
- --read-from-remote-serverã®ã¿ã®å ´å
- server_idã¨ãã¦0ãããã©ã«ãã§ä½¿ç¨ããã¾ããçµäºã次第æ¥ç¶ãåãããããã§ãã
- --read-from-remote-server 㨠--stop-neverã®ä¸¡æ¹ã®å ´å
- server_idã¨ãã¦65535ãããã©ã«ãã§ä½¿ç¨ããã¾ãã--stop-never-slave-server-idãªãã·ã§ã³(çç¥å½¢ç¡ã)ã§server_idãæå®å¯è½ã§ãã
ä»å使ç¨ãã¦ããã¦ã¼ã¶ã®æ¨©é㯠REPLICATION SLAVE, REPLICATION CLIENTã®2ã¤ã®ã¿ã§ãã¬ããªã±ã¼ã·ã§ã³ç¨ã¦ã¼ã¶ã¨åã権éã§ç¢ºèªãã¦ãã¾ãã
æå®ãããã¤ããªãã°ã®ã³ãã¼
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 --raw mysql-bin.000001 Enter password: # # ls -l total 4 -rw-rw-r-- 1 root root 1698 Nov 14 02:40 mysql-bin.000001 #
ãã®å ´åãå®è¡ããã«ã¬ã³ããã£ã¬ã¯ããªã«mysql-bin.000001ã¨ããåä¸ãã¡ã¤ã«åã§ä¿åããã¾ããã¾ãã以ä¸ã®ããã«è¤æ°ãã¡ã¤ã«ãæå®ããäºã§ã¾ã¨ãã¦ã³ãã¼ãå¯è½ã§ãã
# /usr/local/mysql/bin/mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 \ --raw mysql-bin.000001 mysql-bin.000002 Enter password: # ls -l total 8 -rw-rw-r-- 1 root root 1698 Nov 14 02:42 mysql-bin.000001 -rw-rw-r-- 1 root root 470 Nov 14 02:42 mysql-bin.000002 #
ãªãã--rawãªãã·ã§ã³(çç¥å½¢ç¡ã)ãæå®ããªãå ´å㯠mysqlbinlog ./mysql-bin.000001 ãå®è¡ããå ´åã¨åæ§ãããã¹ãã¨ãã¦æ¨æºåºåããã¾ãã
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 mysql-bin.000002 Enter password: /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #121114 2:35:55 server id 237 end_log_pos 120 CRC32 0xc99a96dd Start: binlog v 4, server v 5.6.8-rc-log created 121114 2:35:55 BINLOG ' +4SiUA/tAAAAdAAAAHgAAAAAAAQANS42LjgtcmMtbG9nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAd2W msk= '/*!*/; # at 120 #121114 2:35:55 server id 237 end_log_pos 191 CRC32 0xa67e4728 Previous-GTIDs # C4F64A91-2A2B-11E2-9084-5254003E1CEC:1-6 # at 191 #121114 2:36:02 server id 237 end_log_pos 239 CRC32 0x97ca0ec0 GTID [commit=yes] SET @@SESSION.GTID_NEXT= 'C4F64A91-2A2B-11E2-9084-5254003E1CEC:7'/*!*/; # at 239 #121114 2:36:02 server id 237 end_log_pos 326 CRC32 0xce3aa2a0 Query thread_id=19 exec_time=0 error_code=0 SET TIMESTAMP=1352828162/*!*/; SET @@session.pseudo_thread_id=19/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1075838976/*!*/; 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=33/*!*/; SET @@session.time_zone='SYSTEM'/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; BEGIN /*!*/; # at 326 #121114 2:36:02 server id 237 end_log_pos 439 CRC32 0x3b6fbcf9 Query thread_id=19 exec_time=0 error_code=0 use `test`/*!*/; SET TIMESTAMP=1352828162/*!*/; insert into test values (NOW()) /*!*/; # at 439 #121114 2:36:02 server id 237 end_log_pos 470 CRC32 0x32ddc489 Xid = 217 COMMIT/*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; #
ã³ãã¼ãããã¤ããªãã°ãã³ãã¼å ãµã¼ãããåé¤ããã¦ããå ´å(expire_logs_daysãpurge master logs toçã§)ã¯ã¨ã©ã¼ã¨ãªãã¾ãã
ERROR: Got error reading packet from server: Could not find first log file name in binary log index file
æå®ãããã¤ããªãã°ä»¥éãå ¨ã¦ã³ãã¼ãã
--to-last-logãªãã·ã§ã³(-t)ã使ç¨ããã¨æå®ãããã¤ããªãã°ä»¥éãå ¨ã¦ã³ãã¼ããäºãåºæ¥ã¾ãã
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 \ --raw --to-last-log mysql-bin.000004 Enter password: # ls -l total 16 -rw-rw-r-- 1 root root 517 Nov 14 02:51 mysql-bin.000004 -rw-rw-r-- 1 root root 796 Nov 14 02:51 mysql-bin.000005 -rw-rw-r-- 1 root root 517 Nov 14 02:51 mysql-bin.000006 -rw-rw-r-- 1 root root 470 Nov 14 02:51 mysql-bin.000007 #
æå®ãããã¤ããªãã°ä»¥éãåæ¢ããã¾ã§ã³ãã¼ãç¶ãã
--stop-neverãªãã·ã§ã³(çç¥å½¢ç¡ã)ã使ç¨ãããã¨ã§ctrl+cçã§åæ¢ããã¾ã§è¿½å ããããã¤ããªãã°ãã³ãã¼ãç¶ããäºãåºæ¥ã¾ãã
å®è¡åã®ã³ãã¼å ã®MySQLã®ç¶æ
mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 1698 | | mysql-bin.000002 | 517 | | mysql-bin.000003 | 796 | | mysql-bin.000004 | 517 | | mysql-bin.000005 | 796 | | mysql-bin.000006 | 517 | | mysql-bin.000007 | 470 | +------------------+-----------+ 7 rows in set (0.00 sec) mysql>
--stop-neverã使ç¨ãã¦ãã¤ããªãã°ãã³ãã¼
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 --raw --stop-never mysql-bin.000001 Enter password:
ã³ãã¼ãããã¤ããªãã°ã確èª
# ls -l total 28 -rw-rw-r-- 1 root root 1698 Nov 14 03:03 mysql-bin.000001 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000002 -rw-rw-r-- 1 root root 796 Nov 14 03:03 mysql-bin.000003 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000004 -rw-rw-r-- 1 root root 796 Nov 14 03:03 mysql-bin.000005 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000006 -rw-rw-r-- 1 root root 439 Nov 14 03:03 mysql-bin.000007 #
ã³ãã¼å ã®MySQLã§flush binary logsãå®è¡
mysql> flush binary logs; Query OK, 0 rows affected (0.03 sec) mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 1698 | | mysql-bin.000002 | 517 | | mysql-bin.000003 | 796 | | mysql-bin.000004 | 517 | | mysql-bin.000005 | 796 | | mysql-bin.000006 | 517 | | mysql-bin.000007 | 517 | | mysql-bin.000008 | 191 | +------------------+-----------+ 8 rows in set (0.00 sec) mysql>
ã³ãã¼å ã§mysql-bin.000008ãã³ãã¼ããã¦ããäºã確èª
# ls -l total 32 -rw-rw-r-- 1 root root 1698 Nov 14 03:03 mysql-bin.000001 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000002 -rw-rw-r-- 1 root root 796 Nov 14 03:03 mysql-bin.000003 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000004 -rw-rw-r-- 1 root root 796 Nov 14 03:03 mysql-bin.000005 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000006 -rw-rw-r-- 1 root root 517 Nov 14 03:03 mysql-bin.000007 -rw-rw-r-- 1 root root 120 Nov 14 03:03 mysql-bin.000008 #
ä¸è¨ã®ãããªæ¯ãèãã¨ãªãã¾ãã®ã§--rawãªãã·ã§ã³ã使ç¨ããªãå ´åãåãæµãç¶æ ã«åºæ¥ã¾ãã
ã¾ããå¾æ¥éãã«éå§ãã¸ã·ã§ã³ãæå®å¯è½ã§ãã®ã§ä¾ãã°mysqldumpã³ãã³ã㧠--single-transaction --master-data=2ãªãã·ã§ã³ã使ç¨ãã¦ãã³ããåå¾ããå ´åããã¼ã«ãã©ã¯ã¼ããªã«ããªç¨ã«ä»¥ä¸ã®ããã«å¿ è¦ãªãã¤ããªãã°ãã³ãã¼ããäºãå¯è½ã§ãã
ãã³ããã¡ã¤ã«ã«ã¯ä»¥ä¸ã®ããã«è¨è¼ããã¦ããã¨ãã¾ãã
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000008', MASTER_LOG_POS=749;
æå®ãããã¸ã·ã§ã³ããã³ãã¼ããã
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 \ --stop-never --raw --start-position=749 mysql-bin.000008
å ¬å¼ããã¥ã¡ã³ãã«ãè¨è¼ããã¦ãã¾ããã以ä¸ã®ããã«ãããã¨ã§ãªã¹ãã¢å¾ã®MySQLã«ç´æ¥ãã¤ããªãã°ãæµãè¾¼ãäºãå¯è½ã§ãã
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 \ --start-position=749 mysql-bin.000008 mysql-bin.000009 | mysql --host=host_name -u root -p
ãã®ä»ãªãã·ã§ã³
ããã¾ã§ã«è¨è¼ãããªãã·ã§ã³ã§åºæ¬çãªäºã¯å¯è½ãã¨æãã¾ããã以ä¸ã®ããã«ã¡ãã£ã¨ä¾¿å©ãªãªãã·ã§ã³ãããã¾ãã
ä¿åãããã¤ããªãã°ã«ããªãã£ãã¯ã¹ãä»ä¸ãã
--result-fileãªãã·ã§ã³(-r)ã使ç¨ããäºã§ããªãã£ãã¯ã¹ãä»ä¸åºæ¥ã¾ããã³ãã¼å ã¨ãªããµã¼ãã®æ å ±ãä»ããã®ãããããä¸è¬çãã¨ã
# mysqlbinlog -urepl -p --read-from-remote-server --host=192.168.1.237 \ --to-last-log --raw --result-file=DBM- mysql-bin.000001 Enter password: # ls -l total 32 -rw-rw-r-- 1 root root 1698 Nov 14 03:33 DBM-mysql-bin.000001 -rw-rw-r-- 1 root root 517 Nov 14 03:33 DBM-mysql-bin.000002 -rw-rw-r-- 1 root root 796 Nov 14 03:33 DBM-mysql-bin.000003 -rw-rw-r-- 1 root root 517 Nov 14 03:33 DBM-mysql-bin.000004 -rw-rw-r-- 1 root root 796 Nov 14 03:33 DBM-mysql-bin.000005 -rw-rw-r-- 1 root root 517 Nov 14 03:33 DBM-mysql-bin.000006 -rw-rw-r-- 1 root root 517 Nov 14 03:33 DBM-mysql-bin.000007 -rw-rw-r-- 1 root root 749 Nov 14 03:33 DBM-mysql-bin.000008 #
binlog_checksumã«ãããã§ãã¯ãæå¹ã«ãã
--verify-binlog-checksumãªãã·ã§ã³(-c)ã使ç¨ããäºã§å¯è½ãªããã§ãã解説ãå°ãªãã¦åã£ã¦ããè¥å¹²æªããã§ããbinlog_checksumãªãã·ã§ã³(ããã©ã«ãCRC32)ã«ã¦ãã§ãã¯ãããã®ã¨èãããã¾ãã
.mylogin.cnfã使ç¨ãã¦ãã°ã¤ã³æ å ±ãçç¥
mysql_config_editorã³ãã³ãã§äºãæå®ã®.mylogin.cnfãä½æãã¦ãããã¨ã«ããã--login-pathãªãã·ã§ã³(çç¥å½¢ç¡ã)ã使ãäºã§ãã°ã¤ã³æ å ±ãçç¥ããäºãå¯è½ã§ãã
以ä¸ã®ããã«dbmã¨ããlogin-pathã§ä½æãã¾ãã
# mysql_config_editor set --login-path=dbm --host=192.168.1.237 --user=repl --password Enter password: #
å®è¡å¾ãrootã®å ´åã¯/root/.mylogin.cnfãã¡ã¤ã«ãä½æããã¾ããä½æããå 容ã¯ä»¥ä¸ã®ããã«ç¢ºèªå¯è½ã§ãã
# mysql_config_editor print --all [dbm] user = repl password = ***** host = 192.168.1.237 #
--login-pathã使ç¨ããå ´åã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
# mysqlbinlog --login-path=dbm --read-from-remote-server \ --to-last-log --raw --start-position=749 mysql-bin.000008 # ls -l total 12 -rw-rw-r-- 1 root root 167 Nov 14 04:08 mysql-bin.000008 -rw-rw-r-- 1 root root 517 Nov 14 04:08 mysql-bin.000009 -rw-rw-r-- 1 root root 470 Nov 14 04:08 mysql-bin.000010 #
ãã®ããã«ã ãã¶ãã£ãããã¾ããã¦ã¼ã¶æ å ±ã»ãã¹ã¯ã¼ããå ¥åããå¿ è¦ããªãã®ã§ãã楽ã§ãããèªåå®è¡ã®ããã«ãã¹ã¯ã¼ããå¹³æã§ä¿åããå¿ è¦ããªãããmysql_config_editorã³ãã³ããåå¨ããªãã£ããããããã»ãã¥ã¢ã«ãããã¨ãåºæ¥ã¾ãã
ã¾ã¨ã
MySQL5.6ããã¯gtidã追å ããããã¨ãããããã¤ããªãã°ã®ããã¯ã¢ããã¯ä»¥åã®ãã¼ã¸ã§ã³ããã¯å¿
è¦æ§ãä¸ãã£ãã¨æãã¾ãã®ã§mysqlbinlogã³ãã³ãã«ããããã¯ã¢ããã¯ãããã使ãããã®ã§ã¯ãªããã¨æãã¾ãã
ããã¾ã§ã§ããã¤ããªãã°ã®ããã¯ã¢ãããå¸æãããæã¯å®éã«ãã£ãããããã®ä½æ¥ãçµæ§æ¥½ã«ãªãã¨æãã¾ããrsyncãªãscpãªãã®ã·ã§ã«ã¹ã¯ãªãããæ¸ããªãã¦è¯ãã ãã§ãã©ãã ã楽ãâ¦
å人çã«ã¯rsyncã³ãã³ãã®--bwlimitçãªãªãã·ã§ã³ããã£ããè¯ãã®ã«ãªãã¨ãä¸æ°ã«ã³ãã¼å ã«å¯¾ãã¦èªã¿åãè² è·ããããã®ã¯ãµã¼ãã¹ä¸ã ã¨ã¡ãã£ã¨â¦ ã¨ãªãã¾ãã®ã§ã
gtidã«çµ¡ã¿ãããªãªãã·ã§ã³ãè¦åãããããããä½ãããéè¦ãããªç¹ããã£ããä½ãããã¾ãæ¸ãã¨æãã¾ãã