本文是对mysql主从同步http://dnuser.blog.51cto.com/4863891/1263570的补充,只是增加了相互同步

 

ServerA:192.168.1.251
ServerB:192.168.1.252

 

ServerA:

mysql>grant replication slave on *.* to backdata@'192.168.1.252' identified by "backpass";

[root@ServerA ~]# cat /etc/my.cnf
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

log-bin=mysql-bin
binlog_format=mixed

server-id       = 2
expire_logs_days=7
binlog-do-db=vv
binlog-do-db=vvf_mall
binlog-ignore-db=mysql
binlog-ignore-db=information_schema

#自增主键1,3,5,7.........
auto_increment_offset = 1
auto_increment_increment = 2

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

在ServerB上执行:
mysql> show master status;
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql-bin.000025 |      106 | vv,vvf_mall  | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
在ServerA上执行:
mysql>change master to  master_host='192.168.1.252', 

master_user='backdata',master_password='backpass',master_port=3306,master_log_file='mysql-bin.000025', 

master_log_pos=106;

mysql>slave start;
mysql>show slave status \G;

 Slave_IO_Running: Yes           
 Slave_SQL_Running: Yes

 

 

 

ServerB:

mysql>grant replication slave on *.* to backdata@'192.168.1.251' identified by "backpass";

[root@ServerB ~]# cat /etc/my.cnf
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M


log-bin=mysql-bin
binlog_format=mixed

server-id       = 2
expire_logs_days=7
binlog-do-db=vv
binlog-do-db=vvf_mall
binlog-ignore-db=mysql
binlog-ignore-db=information_schema

#自增主键2,4,6,8.......
auto_increment_offset = 2
auto_increment_increment = 2

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

在ServerA上执行:
mysql> show master status;
+------------------+----------+--------------+--------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         |
+------------------+----------+--------------+--------------------------+
| mysql-bin.000005 |      108 | vv,vvf_mall  | mysql,information_schema |
+------------------+----------+--------------+--------------------------+
1 row in set (0.00 sec)
在ServerB上执行:
mysql>change master to  master_host='192.168.1.251', 

master_user='backdata',master_password='backpass',master_port=3306,master_log_file='mysql-bin.000005', 

master_log_pos=108;

mysql>slave start;
mysql>show slave status \G;

 Slave_IO_Running: Yes           
 Slave_SQL_Running: Yes