centos7mysql5.7读写分离配置

1:创建用户给slave使用slave将会通过这个账号同步数据

修改用户密码等级:

set global validate_password_length=1;

set global validate_password_policy=0;

创建用户:

create user repl identified by 'repl';

2:给账号权限

grant replication slave on *.* to 'repl'@'%' identified by 'repl';
3:使用命令vi /etc/my.cnf打开mysql配置文件并添加:

log-bin=mysql-bin
server-id=217
4:重启mysql:

systemctl start mysqld

登陆mysql使用命令show master status查询对应日志文件和起始读取

5:使用命令vi /etc/my.cnf打开mysql配置文件在slave上配置文件里面加如下配置

server-id=217
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
read_only=1

6:登陆mysql

7:运行命令: 
 change master to master_host='master的ip',master_port=端口号,master_user='先前创建的账号',master_password='对应密码',master_log_file='日志文件名称',master_log_pos=读取起始位;

 change master to master_host='192.168.31.217',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000001',master_log_pos=154;

8:在mysql里面运行命令启动服务:

start slave;

9:show slave status\G;查看连接状态

都为yes,表示成功了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值