快速配置MySQL -GTID 主从,只需要1分钟。你要做的就是,把下面两段代码,先在主机上运行,后在从机上运行。
当然,这里省去了MySQL的安装过程,如果你需要快速安装MySQL ,可以运行下面的全自动脚本。全自动安装mysql脚本: https://www.cnblogs.com/ypeuee/p/13235307.html
主库配置
#修改配置 启动gtid sed -i -e ‘6a server-id = 1‘ /etc/my.cnf sed -i -e ‘7a gtid_mode=on‘ /etc/my.cnf sed -i -e ‘8a enforce_gtid_consistency=on‘ /etc/my.cnf sed -i -e ‘9a log-slave-updates=1‘ /etc/my.cnf sed -i -e ‘10a log-bin=master-bin‘ /etc/my.cnf sed -i -e ‘11a log-bin-index = master-bin.index‘ /etc/my.cnf sed -i -e ‘12a relay-log = relay-log‘ /etc/my.cnf sed -i -e ‘13a relay-log-index = relay-log.index‘ /etc/my.cnf sed -i -e ‘14a binlog_format=row‘ /etc/my.cnf #重启mysql systemctl restart mysqld; #登录 mysql mysql -uroot -p123456 #创建用户 grant replication slave on *.* to ‘rep‘@‘192.168.3.%‘ identified by ‘123456‘; flush privileges;
#复制到此处
从机配置
#修改配置 启动gtid sed -i -e ‘6a server-id = 2‘ /etc/my.cnf sed -i -e ‘7a gtid_mode=on‘ /etc/my.cnf sed -i -e ‘8a enforce_gtid_consistency=on‘ /etc/my.cnf sed -i -e ‘9a log-slave-updates=1‘ /etc/my.cnf sed -i -e ‘10a log-bin=master-bin‘ /etc/my.cnf sed -i -e ‘11a log-bin-index = master-bin.index‘ /etc/my.cnf sed -i -e ‘12a relay-log = relay-log‘ /etc/my.cnf sed -i -e ‘13a relay-log-index = relay-log.index‘ /etc/my.cnf sed -i -e ‘14a binlog_format=row‘ /etc/my.cnf #重启mysql systemctl restart mysqld; #登录 mysql mysql -uroot -p123456 #连接到主机 change master to master_host=‘192.168.3.160‘,master_user=‘rep‘,master_password=‘123456‘,master_port=3306,master_auto_position=1; #等待2秒 select sleep(2); #启动主从 start slave; #等待2秒 select sleep(2); #查看状态 show slave status \G
#复制到此处