mysql 简单主从

主服务器master

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin   #必须开启log-bin
server-id=129       #服务器ID

  

从服务器slave

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
log-bin=mysql-bin   #开启log-bin(可选)
server-id=129       #服务器ID
[root@localhost ~]# systemctl restart mysqld  #主从服务器
 

mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by '123456';  #主服务器授权账号
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      439 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

  

#查看master状态
mysql> stop slave;
mysql>change master to \
master_host='192.168.100.129',master_user='mysync',master_password='123456', \
master_log_file='mysql-bin.000004',master_log_pos=308;
mysql> stop slave;
mysql> show slave status\G  #查看slave状态
   Slave_IO_Running: Yes  #必须为Yes
   Slave_SQL_Running: Yes #必须为Yes

如果在master 也配置 slave 架构就成了主主模式 需要注意数据一致性的问题

  

虚拟机克隆需要重新生成auto.cnf

[root@localhost ~]# mv /var/lib/mysql/auto.cnf /tmp
[root@localhost ~]# systemctl restart mysqld

  

posted @ 2017-05-19 17:03  三木燕  阅读(159)  评论(0编辑  收藏  举报