2014/04/23

mysql GTID replication セットアップ

■cold start

1If replication is already running, synchronize both servers by making them read-only.
=>SET @@global.read_only = ON;
2Stop both servers.
=>mysqladmin -uusername -p shutdown
3Restart both servers with GTIDs, binary logging, and slave update logging enabled, and with statements that are unsafe for GTID-based replication disabled. In addition, the servers should be started in read-only mode, and the slave SQL and I/O threads should be prevented from starting on the slave.
=>mysqld_safe --gtid_mode=ON --log-bin --log-slave-updates  --disable-gtid-unsafe-statements&
4Instruct the slave to use the master as the replication data source and to use auto-positioning, and then start the slave
=>
mysql> CHANGE MASTER TO
     >     MASTER_HOST = host,
     >     MASTER_PORT = port,
     >     MASTER_USER = user,
     >     MASTER_PASSWORD = password,
     >     MASTER_AUTO_POSITION = 1;
     START SLAVE;
5Disable read-only mode on both servers, so that they can once again accept updates.
=>SET @@global.read_only = OFF;


・Use the mysql client to import a dump file created with mysqldump. Use the --master-data option to include binary logging information and --set-gtid-purged (available in MySQL 5.6.9 and later) to AUTO (the default) or ON, to include information about executed transactions
・Stop the slave, copy the contents of the master's data directory to the slave's data directory, then restart the slave.
・Injecting empty transactions
==>
SET GTID_NEXT='aaa-bbb-ccc-ddd:N';

BEGIN;
COMMIT;

SET GTID_NEXT='AUTOMATIC';


==>よくわかない。。。試しないと。。。

制約:
・the storage engine must be transactional
・CREATE TABLE ... SELECT is not supported when using GTID-based replication.
・sql_slave_skip_counter is not supported when using GTIDs



■simple-setup
==>初期段階でこれはいい。設定だけでSLAVEは自動的にMASTERを追いかける。



■MASTERのSnapshotを取り入れ、その分の時間を節約する。

1DUMP
★MASTERのDUMPを取る
mysqldump --master-data=ON --set-gtid-purged=ON

--master-data
==>Use this option to dump a master replication server to produce a dump file that can be used to set up another server as a slave of the master.
The --master-data option automatically turns off --lock-tables. It also turns on --lock-all-tables, unless --single-transaction also is specified, in which case, a global read lock is acquired only for a short time at the beginning of the dump (see the description for --single-transaction). In all cases, any action on logs happens at the exact moment of the dump

In all cases, any action on logs happens at the exact moment of the dump.

★SLAVEはrestoreする
mysql

2ファイルコピー
Stop the slave, copy the contents of the master's data directory to the slave's data directory, then restart the slave.
=>auto.cnf、mysql.sock、mysql.pidを削除してから。。

3mysqlbinlogの方法