master server Master
[[email protected] ~]# vim /etc/my.cnf[mysqld]log-bin=mysql-bin #必须开启log-binserver-id=129 #服务器ID
from server slave
[[email protected] ~]# vim /etc/my.cnf[mysqld]log-bin=mysql-bin #开启log-bin(可选)server-id=129 #服务器ID
[root@localhost ~]# systemctl restart mysqld #主从服务器
mysql> GRANT REPLICATION SLAVE on * * to ' Mysync ' @ '% ' identified by ' 123456 '; #主服务器授权账号
mysql> Show master status;+------------------+----------+------ --------+------------------+-------------------+| File | Position | binlog_do_db | binlog_ignore_db | Executed_gtid_set |+------------------+----------+--------------+------------------+-------------------+| mysql-bin.000001 | 439 | | | |+------------------+----------+--------------+------------------+------------------ -+1 row in set (0.00 sec" #查看master状态
mysql> stop slave;mysql>change master to master_host=‘192.168.100.129‘,master_user=‘mysync‘,master_password=‘123456‘, master_log_file=‘mysql-bin.000004‘,master_log_pos=308;mysql> stop slave;mysql> show slave status\G #查看slave状态 Slave_IO_Running: Yes #必须为Yes Slave_SQL_Running: Yes #必须为Yes如果在master 也配置 slave 架构就成了主主模式 需要注意数据一致性的问题
Virtual machine cloning requires rebuilding auto.cnf
[root@localhost ~]# mv /var/lib/mysql/auto.cnf /tmp[root@localhost ~]# systemctl restart mysqld
MySQL Simple master and slave