1 my.cnf文件 配置

  binlog_format = ROW
  log_bin_trust_function_creators=1
  log-error = /usr/local/mysql/data/hostname.err
  log-bin = /usr/local/mysql/arch/mysql-bin
  expire_logs_days = 7

#server-id需要与master不一致

  server-id = 1739

2 在master主机上创建同步用户

grant replication slave on *.* to sync@'%' identified by 'Zj123456!';
flush privileges;

3 查看主机上master status

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 989 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql>

4  从库上执行master

mysql>
change master to
master_host='192.168.56.100',
master_port=3306,
master_user='sync',
master_password='Zj123456!',
master_log_file='mysql-bin.000005',
master_log_pos=3820;
     
mysql> start slave;
 
mysql>show slave status\G;

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.100
Master_User: sync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 3820
Relay_Log_File: relay-log.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: omsprd.%,wmsb01.%,wmsb02.%,wmsb03.%,wmsb04.%,wmsb05.%,wmsb06.%,wmsb07.%,wmsb08.%,wmsb08.%,wmsb09.%,wmsb10.%,wmsb11.%,wmsb27.%,wmsb31.%,wmsb32.%,wmsb33.%,wmsb34.%,wmsb35.%
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 3820
Relay_Log_Space: 521
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1739
Master_UUID: 71f0e5b7-16f2-11e9-949d-0800271f440a
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)

ERROR:
No query specified

看到这两行,表示成功

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

5 验证同步是否成功

查看my.cnf 设置同步的数据库与表

#need to sync tables
replicate-wild-do-table=omsprd.%
replicate_wild_do_table=wmsb01.%
replicate_wild_do_table=wmsb02.%
replicate_wild_do_table=wmsb03.%
replicate_wild_do_table=wmsb04.%
replicate_wild_do_table=wmsb05.%
replicate_wild_do_table=wmsb06.%
replicate_wild_do_table=wmsb07.%
replicate_wild_do_table=wmsb08.%
replicate_wild_do_table=wmsb08.%
replicate_wild_do_table=wmsb09.%
replicate_wild_do_table=wmsb10.%
replicate_wild_do_table=wmsb11.%
replicate_wild_do_table=wmsb27.%
replicate_wild_do_table=wmsb31.%
replicate_wild_do_table=wmsb32.%
replicate_wild_do_table=wmsb33.%
replicate_wild_do_table=wmsb34.%
replicate_wild_do_table=wmsb35.%

验证

主库上操作
mysql> create database omsprd;
Query OK, 1 row affected (0.00 sec)

mysql> use omsprd;
Database changed

mysql> CREATE TABLE `t_banner` (
-> `id` int(11) NOT NULL AUTO_INCREMENT,
-> `img` varchar(128) NOT NULL,
-> `url` varchar(128) NOT NULL,
-> `creater` varchar(10) NOT NULL,
-> `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
-> `name` varchar(64) NOT NULL,
-> `is_delete` int(11) NOT NULL DEFAULT '0',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='广告';
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t_banner(id,img,url,creater,name) values(1,'zhangsan', 'php001','zhangjin','test');
Query OK, 1 row affected (0.00 sec)

mysql>

从库查询

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| omsprd |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql> use omsprd;
Database changed
mysql> show tables;
+------------------+
| Tables_in_omsprd |
+------------------+
| t_banner |
+------------------+
1 row in set (0.00 sec)

mysql> select * from t_banner;
+----+----------+--------+----------+---------------------+------+-----------+
| id | img | url | creater | create_time | name | is_delete |
+----+----------+--------+----------+---------------------+------+-----------+
| 1 | zhangsan | php001 | zhangjin | 2019-01-13 06:58:58 | test | 0 |
+----+----------+--------+----------+---------------------+------+-----------+
1 row in set (0.00 sec)

mysql>

期间遇到的问题

1 mysql从库启动不了,与主库的uuid一致,删除data文件,重新初始化搞定

2 Slave_IO_Running: NO

  第一次 密码不对,修改后还是不可以

  第二次 重新刷新用户名赋予权限,远程登录可以,重新change to master后可以搞定。

MySQL5.7主从复制配置的更多相关文章

  1. centos 7 Mysql5.7 主从复制配置

    1.环境 Centos 7 Mysql 5.7 Master  192.168.1.71 Slave01 192.168.1.72 2.分别配置master,slave01 # vi /etc/my. ...

  2. MySQL5.7 主从复制配置

    一.主从复制原理 MySQL 主从复制是一个异步的复制过程,主库发送更新事件到从库,从库读取更新记录,并执行更新记录,使得从库的内容与主库保持一致.每一个主从复制的连接,都有三个线程.拥有多个从库的主 ...

  3. mysql5.7主从复制配置——读写分离实现

    为什么使用主从架构?1.实现服务器负载均衡:2.通过复制实现数据的异地备份:3.提高数据库系统的可用性:4.可以分库[垂直拆分],分表[水平拆分]: 主从配置的前提条件1.MySQL版本一致:2.My ...

  4. mysql5.7在windows下面的主从复制配置

    目标:自动同步Master 服务器上面的Demo数据库到Slave 服务器的Demo数据库中. 对于一些操作系统比较强而使用频率又不高的东西,往往好久不去弄就忘记了,所以要经常记录起来,方便日后查阅. ...

  5. MySQL5.7 Replication主从复制配置教程

    最近配置mysql5.7主从复制的时候碰到了些问题,老老实实按老版本的步骤配置会有错误,后来自己查看了官方文档,才解决了问题,在这里总结一下5.7的配置步骤, 大体步骤跟老版本的还是一样的,只是有一些 ...

  6. mysql5.7.26做主从复制配置

    一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.主 ...

  7. Docker安装mysql5.7并且配置主从复制

    Docker安装mysql5.7并且配置主从复制 一.拉取mysql镜像 二.创建文件docker.cnf 2.1 mysql主机(192.168.21.55:3307) 2.1.1 创建文件夹 2. ...

  8. MySQL5.6主从复制最佳实践

    MySQL5.6     主从复制的配置  环境 操作系统:CentOS-6.6-x86_64 MySQL 版本:mysql-5.6.26.tar.gz 主节点 IP:192.168.31.57    ...

  9. mysql5.7 主从复制的正常切换【转】

    目前环境如下: master server IP:172.17.61.131 slave server IP:172.17.61.132 mysql version: mysql-5.7.21-lin ...

随机推荐

  1. Lodop打印设计(PRINT_DESIGN)里的快捷键

    Lodop打印控件,给开发人员提供了可视化编辑工具,编辑后可生成代码,然后复制到自己程序代码中,让开发更简单,打印设计中有一些快捷键也能让开发更便捷. 打印设计快捷键:ctrl 多个选中Shift 左 ...

  2. mysql关于binlog日志的操作

    查看binlog日志选项和存储位置: mysql> show variables like 'log_%'; 1.查看所有binlog日志列表 mysql> show master log ...

  3. Fantasy of a Summation LightOJ - 1213 (快速幂)

    题意: 首先 只看第一层循环的A[0],是不是用了nk-1次  A[1]也是用了nk-1次······ 所以 第一层的sum(A[i]的和) 一共用了nk-1 所以第一层为sum * nk-1 因为又 ...

  4. (转)二分图匹配匈牙利算法与KM算法

    匈牙利算法转自于: https://blog.csdn.net/dark_scope/article/details/8880547 匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名 ...

  5. hdu 4417 Super Mario (主席树)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ...

  6. UVa - 10339

    It has been said that a watch that is stopped keeps better time than one that loses 1 second per day ...

  7. MT【206】证明整数数列

    已知方程$x^3-x^2-x+1=0$,的三根根为$a,b,c$,若$k_n=\dfrac{a^n-b^n}{a-b}+\dfrac{b^n-c^n}{b-c}+\dfrac{c^n-a^n}{c-a ...

  8. 自学Linux Shell13.1-命令行参数

    点击返回 自学Linux命令行与Shell脚本之路 Bash shell提供了一些不同的方法来从用户处获得数据,包括以下3中方法: 命令行参数(添加在名利后面的数据) 命令行选项(可修改命令行为的单个 ...

  9. XML解析(DOM、ElementTree)及转换为JSON

    xml.dom篇 DOM是Document Object Model的简称,XML 文档的高级树型表示.该模型并非只针对 Python,而是一种普通XML 模型.Python 的 DOM 包是基于 S ...

  10. Linux下定时器

    http://unix8.net/linux%E4%B8%8B%E5%AE%9A%E6%97%B6%E5%99%A8.html 一. 基础知识 1.时间类型.Linux下常用的时间类型有4个:time ...