mysql主从-ms

一、环境准备

1、准备两台安装有mysql的linux服务器

2、安装的mysql版本最好相同

3、配置两台服务器的主机名和IP地址,主机名:master和slave,IP地址:192.168.0.20和192.168.0.19

4、确保两台服务器中mysql的数据一致,如果不一致,通过备份master的数据库,导入到slave中。

二、配置主从

master服务器

1、配置同步授权用户slave,密码:12345

命令:

 1 root@rshine-virtual-machine:~# 
 2 root@rshine-virtual-machine:~# mysql -uroot -padmin@1234
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 88
 5 Server version: 5.5.62-0ubuntu0.14.04.1-log (Ubuntu)
 6 
 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> grant replication slave on *.* to slave@'192.168.0.19' identified by "12345";

2、修改mysql配置文件/etc/mysql/my.cnf

3、重启mysql

命令:

1 /etc/init.d/mysql restart

4、查看master的状态信息

命令:

slave服务器

 1、修改mysql配置文件/etc/mysql/my.cnf

2、重启mysql

命令 :

1 /etc/init.d/mysql restart

3、配置主mysql信息,包括同步账号和密码,IP地址、端口号、以及二进制日志文件名。

命令:

4、查看slave状态

命令:

三、测试主从效果

1、查看主从服务器mysql数据是否一致

 

 从上述结果看,master和slave的数据库数据一致。

2、在master中插入一条数据,查看slave中会不会同步这条数据

3、查看slave的数据

 

由此可得,slave同步了master插入的一条数据。实现了主从同步。

 

posted @ 2019-07-18 14:35  龙翔浅帝  阅读(367)  评论(0编辑  收藏  举报