当前位置:Gxlcms > 数据库问题 > mysql 5.7主从配置

mysql 5.7主从配置

时间:2021-07-01 10:21:17 帮助过:3人阅读

  

主: 192.168.10.144
从:192.168.10.113

 

主:

mysql -u root -p

create user slave;
grant replication slave on *.* to ‘slave‘@‘192.168.10.113‘ identified by ‘mysql‘;

//注解: 192.168.10.113是从机的IP

修改/etc/mysql/mysql.conf.d/mysqld.cnf,如下信息:

技术分享

#重启mysql

service mysql restart;

mysql -u root -p;

show master status;

技术分享

 

 

从:

change master to master_host=‘192.168.10.144‘,master_user=‘slave‘,master_password=‘mysql‘,master_port=3306,MASTER_LOG_FILE=‘mysql-bin.000001‘, MASTER_LOG_POS=603;

//192.168.10.144 主mysql, mysql-bin.000001, 603, 对应的是主服务器上 show master status的结果。

show slave status\G

技术分享

 

 

1. 如果开启远程访问:

在/etc/mysql/mysql.conf.d/mysqld.cnf文件中,注释掉如下:

技术分享

mysql>use mysql;

mysql>update user set host=‘%‘ where user=‘root‘;

mysql>flush privileges; -- 刷新MySQL的系统权限相关表;

 

2. 去掉 slave所赋予的权限。

stop slave;

change master to master_host=‘ ‘;

start slave;

 

 

参考:

 

http://rainbow702.iteye.com/blog/1558412

http://blog.yuansc.com/2016/02/17/mysql-5-7%E4%BA%92%E4%B8%BA%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E9%85%8D%E7%BD%AE/

http://www.cfei.net/archives/1066

mysql 5.7主从配置

标签:

人气教程排行