mariadb(mysql)主从备份设置

主服务器: 192.168.1.8

备份服务器: 192.168.1.9

要求主服务器上针对数据库test的任何修改操作都会同步到备份服务器(双击热备)。

操作方法:

1、主服务器设置 vim /etc/my.cnf

[mysqld]下增加配置:

server-id = 8
log-bin=mysql-bin

重启mariadb: systemctl restart mariadb

在主服务器的mysql中为备份服务器的mysql连接创建一个用户:

grant replication slave on . to ‘slave’@‘218.206.70.146’ identified by ‘123456’;
flush privileges;
show master status\G;
可以看到如下结果:

*************************** 1. row ***************************
File: mysql-bin.000034
Position: 245
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

ERROR: No query specified

ERROR: No query specified

2、从服务器配置:

[mysqld]下增加如下配置:

server-id = 9
log-bin=mysql-bin
replicate-do-db = dnoa,kjoa

重启mariadb: systemctl restart mariadb

stop slave;
change master to master_host=‘192.168.1.8’,master_user=‘slave’,master_password=‘password’,master_log_file=‘mysql-bin.000033’,master_log_pos=245;
start slave;
show slave status\G;

你可能感兴趣的:(MySQL)