mysql服务器主从分离

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wt1286331074/article/details/87901902

参考:http://www.php.cn/code/19580.html

首先先两台服务器安装好mysql,同时都开启log-bin写日志功能,主

从分离就是主服务器负责写,多台从服务器负责读就好了。
关闭防火墙service iptables stopsetenforce 0

在my.cnf里面添加server-id=1(主)server-id=76(从)
同步两个数据库和表

主服务器执行:

grant replication slave on *.* to 'mysqlroot'@'%' identified by '111111';// 创建个账号专门用来同步数据
show master status; // 显示日志状态

从服务器执行:
change master to master_host=‘39.108.172.xxx’,master_user=‘mysqlroot’,master_password=‘111111’,master_log_file=‘mysql-bin.000003’,master_log_pos=896;// 注意加黑体的参数

start slave;// 开启从服务
show slave status\G  // 查看从服务状态,下面两个选项都要为Yes (Slave_IO_Running,Slave_SQL_Running)

最后测试,主服务器插入数据,再查看从服务器,OK了

猜你喜欢

转载自blog.csdn.net/wt1286331074/article/details/87901902
今日推荐