在这里我就不说怎么搭建 Mysql 数据库了!如果有需要可以参照我前面的博文。

此博文主要说配置 Linux  数据库   主从   下面我们开始进入正题。

master:192.168.31.200

slave:192.168.31.250

主:192.168.31.200   配置如下:

1.修改   /etc/my.cnf    添加以下配置信息

[mysqld]

log-bin = mysql-bin      ##开启 bin  日志
server-id =1         ##指定
innodb-file-per-table =ON   ##开启独立表空间
skip_name_resolve=ON     ##禁止域名解析(优化的一部分_根据需求)

binlog_do_db=web      ##需要同步的数据库
binlog_do_db=mysql
binlog_do_db=webonline
binlog_do_db=hr

保存   wq

2.重启数据库  

/etc/init.d/mysqld retart

3.进入数据库

[root@mysqlmaster ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.42-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

4.查看 master 值

mysql> show master status;
+------------------+----------+------------------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+------------------------+------------------+-------------------+
| mysql-bin.000002 | 120 | web,mysql,webonline,hr | | |
+------------------+----------+------------------------+------------------+-------------------+
1 row in set (0.01 sec)

5.创建一个用户给主从链接

mysql> grant replication slave on *.* to 'lihong'@'192.168.31.250' identified by '123456';

从:192.168.31.250   配置如下:

1.修改   /etc/my.cnf    添加以下配置信息

[mysqld]

server-id=2
relay-log=relay-log
relay-log-index=relay-log.index
log-bin = mysql-bin
innodb-file-per-table =ON
skip_name_resolve=ON

binlog_do_db=web
binlog_do_db=mysql
binlog_do_db=webonline
binlog_do_db=hr

保存   wq

2.重启数据库  

/etc/init.d/mysqld retart

3.进入数据库

[root@mysqlmaster ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.42-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

4.关闭 slave 

mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

5.创建一个用户给主从链接

mysql> grant replication slave on *.* to 'lihong'@'192.168.31.250' identified by '123456';

6.配置关联的信息

mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.31.200',
-> MASTER_USER='lihong',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-bin.000002',
-> MASTER_LOG_POS=120;

7.开启 slave 

mysql> START SLAVE;
Query OK, 0 rows affected (0.03 sec)

8.查看 slave 是否正常开启了以及是否同步了

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.31.200
Master_User: lihong
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 120
Relay_Log_File: relay-log.000003
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:

9.是否同步成功,查看这两个状态值

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

mysql_主从同步的更多相关文章

  1. mysql数据库主从同步

    环境: Mater:   CentOS7.1  5.5.52-MariaDB  192.168.108.133 Slave:   CentOS7.1  5.5.52-MariaDB  192.168. ...

  2. windows下mysql 主从同步

    半路出家到Java,刚开始听说到说程序支持读写分离感觉特别高大上,也一直没接触 偶然的机会接触到了,就一定得记下来. 今天先讲讲数据库的主从同步,两个好处: 一是读写分离可以用上.比如 写操作就写到主 ...

  3. Redis系列之(二):Redis主从同步,读写分离

    1. Redis主从同步 Redis支持主从同步.数据可以从主服务器向任意数量的从服务器上同步,同步使用的是发布/订阅机制. 2. 配置主从同步 Mater Slave的模式,从Slave向Maste ...

  4. Mysql5.7.13主从同步(复制)配置

    主从同步是分布式mysql数据库相当重要的配置,现在我在虚拟机上完成主从配置,系统是CenterOS6.5,mysql版本是5.7.13 主服务器的ip是192.168.19.139 副服务器的ip是 ...

  5. redis主从同步

    本文是在window环境下的主从同步 1.redis是如何实现主从同步的 redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了master-slave(主从) ...

  6. mysql5.6 主从同步

    主库IP:192.168.220.3 从库IP:192.168.220.4 1.主库配置编辑my.cnf: # For advice on how to change settings please ...

  7. Mysql主从同步遇到的一些问题

    为提供更快的访问速度,在不同的地区增加了一台只供访问的从服务器.因此要将主服务器的数据全部备份过去,并且设置主从同步 假设: 主服务器IP:192.168.1.10 从服务器IP:192.168.1. ...

  8. redis 主从同步

    修改redis.conf配置文件 vi redis.conf 在编辑模式下 输入  /slaveof 来搜索 将slaveof启用 即 将#删除 依次配置所有 slave 并将进程 kill 掉 重启 ...

  9. centos 6.5 中设置mysql 5.1.73 主从同步配置过程

    本文章给大家介绍centos 6.5设置mysql主从同步过程记录,希望文章对各位会带来帮助.  涉及到的centos系统均为虚拟机,VM下安装的版本. 在centos 6.5上设置了mysql主从功 ...

随机推荐

  1. 3D Slicer中文教程(一)—下载及安装方法

    3D Slicer是用于医学图像信息学,图像处理和三维可视化的开源软件平台. 通过国家卫生研究院和全球开发人员社区的支持,二十多年来,Slicer为医生,研究人员和公众提供了免费,强大的跨平台加工工具 ...

  2. k64 datasheet学习笔记22---Direct Memory Access Controller (eDMA)

    0.前言 本文主要介绍DMA相关内容 1.简介 DMA模块包含: 1.一个DMA引擎 源和目的地址的计算 数据搬移 2.本地存储的传输控制描述TCD,对于16个传输通道中的每一个各对应一个TCD 1. ...

  3. orm总结

    x先谈谈java方面的. mybatis优点是基本啥都有了,sql统一管理,只需接口就可以了,缺点是对于复杂语句的执行还是麻烦,一般还是在程序里解决,自带的动态sql功能较弱不说,重点是调式时还是麻烦 ...

  4. $ Django 调API的几种方式

    API调用方式 下面是python中会用到的库.urllib2httplib2pycurlrequestsurllib2 #request import requests, json github_u ...

  5. redis/memcache监控管理工具——treeNMS

    TreeNMS可以帮助您搭建起一套用于redis的监控管理系统,也支持Memcached,让您可以通过web的方式对数据库进行管理,有了它您就可以展示NOSQL数据库.编辑修改内容,另外还配备了sql ...

  6. eclipse格式化代码快捷键失效

    原因是与搜狗输入法的“简繁切换”快捷键冲突(取消搜狗输入法的简繁切换快捷键,即可解决)

  7. Unable to find header files

    在本模块导出头文件时,可以使用如下方式: LOCAL_EXPORT_C_INCLUDE_DIRS := $(MY_DIRECTORY_PATH) LOCAL_EXPORT_C_INCLUDES := ...

  8. 如何使用 Lucene 做网站高亮搜索功能?

    现在基本上所有网站都支持搜索功能,现在搜索的工具有很多,比如Solr.Elasticsearch,它们都是基于 Lucene 实现的,各有各的使用场景.Lucene 比较灵活,中小型项目中使用的比较多 ...

  9. 剑指offer数组3

    面试题11:旋转数组的最小数字 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2 ...

  10. 一JavaScript获取当前月份的前12个月,获取最近的12个月二js实现获取当前月份前的12个月份,格式化后放在一个数组里

    一 ,var dataArr = []; var data = new Date(); var year = data.getFullYear(); data.setMonth(data.getMon ...