Database Version: 5.1.24.
For databases of Version 4. x, go to the relevant documentation.
English document address: http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html
1. When the master server (master) runs normally, create a user dedicated to data synchronization.
Create user 'username' @ 'slave server ip' identified by 'Password ';
Grant replication slave on *. * TO 'username '@ 'slave server ip ';
The username and password (in plain text) will be automatically saved to master.info on the slave server.
2. modify my. cnf on the master server
[Mysqld]
Log-bin = mysql-bin
Server-id = 1
Each mysql host in this image system requires a different server-id (1 ~ Power 32 of 2-1)
PS: If innodb is used, you need to add:
Innodb_flush_log_at_trx_commit = 1
Sync_binlog = 1
PS again: the main service configuration file must not contain skip-networking
PS3: The Master Server Firewall opens port 3306 to the slave server.
Restart mysqld of the master server to make the configuration take effect.
3. Obtain the status information of the master server and copy the data.
3.1 obtain the coordinates of the binary log of the master server
Run a mysql client on the master server,
Mysql> flush tables with read lock;
This will flush all data tables and block all write operations.
For innodb tables, the COMMIT statement is also blocked.
Do not exit the mysql client; otherwise, the read lock will become invalid.
Re-open a mysql client on the master server,
Mysql> show master status;
+ ----- + ---- + ----- + ------ +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+ ----- + ---- + ----- + ------ +
| Mysql-bin.003 | 73 | test | manual, mysql |
+ ----- + ---- + ----- + ------ +
The File field displays the File name of the binary log.
Position shows the offset in this file. Copy the two data.
They represent the replication coordinates at which the slave shoshould begin processing new updates from the master.