systemctl restart mariadb.service systemctl status mariadb.service
4.主从分别创建复制账户
1 2 3 4 5
#创建slave用户密码为slave,从任意IP均可以登录。 #要是需要创建其他密码,从指定IP登录为:grant replication slave on . to ‘slave’@‘192.168.100.%’ identified by ‘pwd@123’; create user 'slave'@'%' identified by 'slave'; grant replication slave on *.* to slave@'%' identified by 'slave'; flush privileges;
flush tables with read lock; show master status; #拿到file和position值 unlock tables; 此时在备机上设置 change master to master_host='主机IP', master_user='slave', master_password='slave', master_port=3306, master_log_file='主机file文件名', master_log_pos=主机position值; start slave; #查看配置状态 show slave status \G #Slave_IO_Running: Yes与Slave_SQL_Running: Yes既正确 如遇到报错Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' 解决办法: stop slave; reset slave; start slave;
2>备机:
flush tables with read lock; show master status; #拿到file和position值 unlock tables; 此时在主机上设置 change master to master_host='备机IP', master_user='slave', master_password='slave', master_port=3306, master_log_file='备机file文件名', master_log_pos=备机position值; start slave; #查看配置状态 show slave status \G #Slave_IO_Running: Yes与Slave_SQL_Running: Yes既正确
#如遇到报错Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file' #解决办法: stop slave; reset slave; start slave;