前提
在centos7上安装并启动mysql
MySQL基础配置
1,进入MySQL,查看有哪些db,指令:show database
2,进入mysql数据库
use mysql;
3,修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
4,开启远程连接功能
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
主主同步
1,主主2台服务器完成以上相同操作
2,第一台主服务器(后面简称DBS1)进入mysql,执行:
GRANT REPLICATION SLAVE ON *.* TO 'root'@'%';
flush privileges;
flush tables with read lock;//锁表保证数据不被操作在设置主主同步时
show master status;
效果如下:
DBS2重复上述步骤,表中File与Position可以与DBS1不一致
3,DBS2备份DBS1操作,假设DBS1的IP地址为:192.168.1.1
unlock tables;
stop slave;
change master to master_host='192.168.1.1',master_user='root',master_password='root',master_log_file='mysql-bin.000001',master_log_pos=1334;
start slave
备注:1,master_log_file,master_log_pos根据DBS1第2步生成表格值更改
2,master_host为DBS1的ip
DBS1备份DBS2同理,主主服务器就完成了。