Use the MySQL image function for Data Synchronization

Source: Internet
Author: User

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.

  • 1
  • 2
  • 3
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.