MySQL主从复制配置

1.  环境html

操做系统:CentOS-7mysql

MySQL:mysql-5.6sql

一台虚拟机又克隆了两台数据库

192.168.102.31  masteride

192.168.102.56  slavespa

192.168.102.36  slave操作系统

启动/中止rest

service  mysqld  start|stop|restart
systemctl  start|stop|restart  mysqld

本机的话,直接mysql就能够进去了

2.  主数据库配置code

第1步:编辑/etc/my.cnf文件,在[mysqld]下增长以下两行设置:server

[mysqld]
log-bin=mysql-bin # 非必需
server-id=1    # 必需

第2步:建立用于数据同步的帐户

CREATE USER 'repl'@'192.168.102.%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.102.%';
FLUSH PRIVILEGES;

第3步:查看master状态

show master status;

3.  从数据库配置

第1步:编辑/etc/my.cnf文件,设置server-id

[mysqld]
server-id=2

第2步:执行同步语句,并启动slave

change master to master_host='192.168.102.31', master_user='repl', master_password='123456', master_log_file='mysql-bin.000001', master_log_pos=514;

第3步:查看slave状态

show slave status\G;

另一台从数据库也是这样设置

4.  验证是否同步成功

在主数据上操做,从数据库中查看

5.  设置只读帐户

mysql> create user 'pig'@'%' identified by '123456';
mysql> grant select on test.* to 'pig'@'%';
mysql> flush privileges;

 

6.  参考

https://dev.mysql.com/doc/refman/5.7/en/replication-options-slave.html

http://www.cnblogs.com/gl-developer/p/6170423.html

http://www.javashuo.com/article/p-gzsohdrv-bw.html

http://www.javashuo.com/article/p-wudtmrxb-ed.html

相关文章
相关标签/搜索