mysql主主同步(AB复制)
互为主MySQL服务器,互为从MySQL服务器 master1 master2 192.168.4.1 192.168.4.2 一、公共配置: server mysql start ping 192.168.4.1 ping 192.168.4.2 关闭 iptables selinux 关闭 selinux
一、 配置master1主配置文件
[[email protected] ~]# vim /etc/my.cnf [mysqld] server_id = 1 log_bin = log log_slave_updates = 1 auto_increment_increment = 2 auto_increment_offset = 1 :wq
service mysql restart \\启动MySQL服务 netstat -anptu | grep :3306 \\查看MySQL状态
mysql -hlocalhost -uroot -p999 mysql> grant replication slave on *.* to [email protected]"192.168.4.2" identified by "123"; mysql> show master status\G; \\查看主服务器的状态
二、配置master2 数据库服务器
mysql -hlocalhost -uroot -p999 \\登陆MySQL服务器 mysql> change master to -> master_host="192.168.4.1", -> master_user="slaveuser", -> master_password="123", -> master_log_file="log.000001", \\依据主服务器的状态(可能每个人的不同,这个不影响) -> master_log_pos=120; Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql> start slave; mysql> show slave status\G; \\查看从服务器的状态 ...... Slave_IO_Running: Yes Slave_SQL_Running: Yes \\出现这俩个说明配置成功 .......
三、 配置master1主配置文件
[[email protected] ~]# vim /etc/my.cnf [mysqld] server_id = 2 log_bin = log1 log_slave_updates = 1 auto_increment_increment = 2 auto_increment_offset = 2 :wq
service mysql restart netstat -anptu | grep :3306 \\查看MySQL状态
mysql -hlocalhost -uroot -p999 \\ master1 和 master2 密码一样 mysql> grant replication slave on *.* to [email protected]"192.168.4.1" identified by "123"; \\授权从MySQL mysql> show master status\G;
四、配置master1 数据库服务器
mysql -hlocalhost -uroot -p999 mysql> change master to -> master_host="192.168.4.1", -> master_user="slaveuser", -> master_password="123", -> master_log_file="log1.000001", -> master_log_pos=120; Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql> start slave; \\启动从MySQL服务器 mysql> show slave status\G; \\查看从服务器的状态 ...... Slave_IO_Running: Yes \\出现这俩个说明配置成功 Slave_SQL_Running: Yes ......
五、测试主从同步
cd /var/lib/mysql/ \\进入MySQL目录路径查看是否生成如下几个文件 master.info relay-log.info log-relay-bin.000001 log-relay-bin.index
时间: 2024-10-19 11:19:21