mysql主从-ms

1、环境准备

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

二、安装的mysql版本最好相同linux

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

四、确保两台服务器中mysql的数据一致,若是不一致,经过备份master的数据库,导入到slave中。数据库

2、配置主从

master服务器

一、配置同步受权用户slave,密码:12345ubuntu

命令:服务器

 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";

二、修改mysql配置文件/etc/mysql/my.cnfide

三、重启mysql测试

命令:spa

1 /etc/init.d/mysql restart

四、查看master的状态信息3d

命令:

slave服务器

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

二、重启mysql

命令 :

1 /etc/init.d/mysql restart

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

命令:

四、查看slave状态

命令:

3、测试主从效果

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

 

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

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

三、查看slave的数据

 

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

相关文章
相关标签/搜索