We are doing web deployment, it tends to involve two or even backup multiple databases, for data security reasons (although the final analysis, nothing but a bunch of 0 1 but the value of the daughter ah), so we obediently do the synchronization! (Heart OS: I have to skewers, and quickly finished eating string of blog)
1, prepare two Linux servers (master and slave)
2, mysql installed
3, in the configuration file /etc/my.cnf(MySQL for mysql.ini) modify open the binary log
log-bin=mysql-bin
Modification method: Open the configuration file
[Mysqld] add content:
server-id = 1 # ensure uniqueness throughout MySQL Cluster
log-bin = / var / log / mysql / mysql-bin.log # log storage position
log-bin-index = binlog.index
4, restart the mysql service
service mysql restart
5, view the configuration is normal
show variables like 'log-bin';
6. Start the master-slave replication
Step 1: Create a landing can from the server MySQL user in the main server
mysql> GRANT REPLICATION SLAVE ON *. * TO 'username' @ 'ip from the server' IDENTIFIED
BY 'password';
mysql>FLUSH PRIVILEGES;
Step two: Check MySQL binary file name and location of the main server
Mysql> SHOW MASTER STATUS;
The third step: inform binary file name and location
In the execution from the server (note punctuation, and finally a semicolon)
Mysql>CHANGE MASTER TO
> MASTER_HOST = 'primary server address',
> MASTER_USER = 'user name created'
> MASTER_PASSWORD = 'password'
> MASTER_LOG_FILE = 'mysql-bin.000048 (according to their modification)',
> MASTER_LOG_POS = 432 (own modification);
From complete replication master;
7, master-slave replication test
In the execution from the server
mysql> START SLAVE; # mysql open copy
> SHOW SLAVE STATUS \ G; # View from the master copy is successful
When you see Slave_IO_Running: YES, Slave_SQL_Running:
YES it indicates a normal status
8, the actual test:
Main landing master MySQL: show database;
Landing from the server MySQL: show databases;
Primary database as follows:
(1) create databases and tables
create database test; use test;
create table tab1(id int auto_increment,name varchar(10),primary key(id));
show databases;
show tables;
If (2) from the database and also view the database table, look at the data synchronization
9, see the error
Into the slave server, run:
mysql> show slave status\G;
.......
Solution one:
Slave_SQL_Running: No
1. The program may be a write operation on the slave
2. After the slave machine may be restarted, transaction rollback caused.
Transaction rollback is generally caused by:
Solution two:
mysql> stop slave;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> start slava;
Note: If it is not in execution from the server inside as follows
mysql>stop slave;
>reset slave;
> Reconfigure synchronization (see Step Six)
>start slave;
So far the database synchronization is complete! (Well, you see, I eat a string!)