配置主服务器:
主服务器1 Ip: 192.168.0.1html
主服务器2 Ip: 192.168.0.2mysql
主服务器1配置sql
2.一、修改mysql配置文件数据库
vim /etc/my.conf
Server-id = 1 #这是数据库ID,此ID是惟一的,主库默认为1,其余从库以此ID进行递增,ID值不能重复,不然会同步出错;vim
log-bin = mysql-bin #二进制日志文件,此项为必填项,不然不能同步数据;服务器
binlog-do-db = slaveDB #须要同步的数据库,若是须要同步多个数据库;ide
则继续添加此项。spa
# binlog-do-db = slaveDB1.net
# binlog-do-db = slaveDB2rest
binlog-ignore-db = mysql 不须要同步的数据库;
····auto-increment-increment = 1初始值为2
····auto-increment-offset = 2 #设置自动增加的字段的偏移量,
2.2配置权限
grant replication slave on *.* to 'user_name'@'192.168.0.2' identified by 'ahaii';
刷新受权当即生效
flush privileges;
开启同步
change master to master_host='192.168.0.225', master_user='user_name', master_password='ahaii', master_log_file='mysql-bin.000001', master_log_pos=80647293;
start slave;
2.三、保存退出!重启mysql服务,使更改生效!
service mysql restart
查看从服务器是否已经成功开启同步:
show slave status\G
相反主服务器2 也要配置主服务器1的权限 除此以外其余配置同样 以上就是主主配置
从数据库配置
在从数据库my.cof里面添加server_id,而后往主数据库添加从数据库的权限,再往从数据库添加
change master to master_host='192.168.0.2', master_user='user_name', master_password='ahaii', master_log_file='mysql-bin.000001', master_log_pos=80647293; start slave;
参考网址:https://www.2cto.com/database/201801/714594.html
参考文档:https://download.csdn.net/download/qq_37996327/10880032
喜欢的能够加群:687942640