mysql master-slave synchronization Notes

master configuration

slave configuration

Master-slave implementation process:

MySQL synchronization realized by three threads (on a master, the slave 2 th)

1: slave IO_THREAD create a connection to the master, the master sends a request binary logs

2: master created Binlog Dump thread (the thread can be viewed by SHOW PROCESSLIST) send a log of contents to IO_THREAD slave

3: IO_THREAD read statement Binlog Dump thread sends the master on the slave, in the log storage relay (relay logs) in

4: Start the slave SQL_THREAD, read relay logs, SQL performs data synchronization is completed.


note:

1. In MySQL4.0.2 before synchronization only two threads (master and each slave a), i.e. without the use of slave relay log

2. If more than one slave, master slave requires two threads for each connection creates a thread, and each slave is always only


===================== ================================================== ======================


Precautions:

1: Master version to be consistent from mysql

2: Enable Sync before, to ensure consistent master data from

3: The method of one of the copied data on the slave master really execute command

mysql>LOAD DATA FROM MASTER

Some restrictions LOAD DATA FROM MASTER command:
A.MySQL version> = 4.0.0
Supports only MyISAM table type B.

C.slave user must have the SUPER privilege

D.master copy the user must have the RELOAD and SUPER privileges
When E.LOAD data, using the global read lock on the master
F. Recommendations master data or allow less time to read when using locks

4: Dual Active mysql is simultaneously configured as two master and slave

5: In order to prevent explode binlog log server, the recommended configuration binlog expired automatically deleted

Configuring using the command

mysql>set global expire_logs_days=8;

Using a configuration file my.cnf

expire_logs_days=8

Check the configuration.

mysql>show variables like 'expire_logs_days';


=============================================================================================


Related command on the primary server:

mysql>show master status\G

mysql>show master status;

mysql>show slave hosts;

mysql>show logs;

mysql>show binlog events;

mysql>show binary logs;

mysql>purge logs to 'log_name';

mysql>purge logs before 'date';

mysql> reset master; // old version flush master

mysql>set sql_log_bin=/xxx;


From the relevant commands on the server:

mysql>slave start;

mysql>slave stop;

mysql> SLAVE STOP IO_THREAD; // this thread to log segments written to the local master

mysql>SLAVE start IO_THREAD;

mysql> SLAVE STOP SQL_THREAD; // this thread to write to the local log to the database

mysql>SLAVE start SQL_THREAD;

mysql>reset slave;

mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER;

mysql>load data from master;

mysql>show slave status; //SUPER,REPLICATION CLIENT

mysql> CHANGE MASTER TO MASTER_HOST = 127.0.0.1, MASTER_PORT = 3306, MASTER_USER = user, MASTER_PASSWORD = pwd; // master dynamically changing information

mysql> PURGE MASTER [before 'date']; master terminal deletion log had synced

mysql> purge binary logs to 'ablelee.000003'; // delete binlog before ablelee.000003, does not contain ablelee.000003

mysql>PURGE MASTER LOGS TO 'mysql-bin.010';

mysql>PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00';


PURGE command syntax

PURGE {MASTER | BINARY} LOGS TO 'log_name'

PURGE {MASTER | BINARY} LOGS BEFORE 'date'

Guess you like

Origin www.cnblogs.com/lonuve/p/11015851.html