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

主服务器的ip是192.168.19.139 副服务器的ip是192.168.19.142

1.主服务器配置

(1)修改my.cnf(注意使用root)

 vim /etc/my.cnf

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log-bin=mysqlbin-log
server_id=
basedir=/home/mysql
user=mysql
datadir=/home/mysql/data
port=
innodb_flush_log_at_trx_commit=
sync_binlog=
log-slave-updates

(2)进入mysql安装目录下的bin,启动mysql

cd /home/mysql/bin ./mysqld

(3)重开启mysql客户端,进入mysql安装目录下的bin,授权副服务器主从复制,用mysqld的好处是可以查看错误。

./mysql -uroot -p mysql> grant replication slave on *.* to test@192.168.19.142 identified by '';

(4)显示主服务器状态

 mysql> show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| mysqlbin-log. | | | | |
+---------------------+----------+--------------+------------------+-------------------+

2.副服务器配置

(1)修改my.cnf(注意使用root)

 vim /etc/my.cnf

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLE
user=mysql
server_id =
replicate-do-db = sbfxd
master-info-file = master.info
relay-log = relay-relay-bin
relay-log-index = relay-relay-bin.index
relay-log-info-file=relay-relay-log.info

(2)进入mysql安装目录下的bin,启动mysql

1 cd /home/mysql/bin 2 ./mysqld

(3)重开启mysql客户端,进入mysql安装目录下的bin,设置slave属性并开始服务

 ./mysql -uroot -p
mysql> change master to master_host='192.168.19.139',master_port= , master_log_file='mysqlbin-log.000019', master_log_pos= , master_bind='', master_user='test',master_password='123';
mysql> start slave;

(4)显示副服务器的状态

 show slave status \G;

             Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.19.139
Master_User: test
Master_Port:
Connect_Retry:
Master_Log_File: mysqlbin-log.
Read_Master_Log_Pos:
Relay_Log_File: relay-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysqlbin-log.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: sbfxd
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: -5ab2-11e6-869b-000c293990c1
Master_Info_File: /home/mysql/data/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:

出现两个yes表示slave可以跑了

3.注意事项:

(1)楼主的虚拟机是通过克隆产生的,所以不需要对mysql进行备份,然后在副服务器上恢复,这步对于数据库极其重要,否则就会出现如下错误:

 --17T03::.579193Z  [ERROR] Slave SQL for channel '': Error executing row event: 'Table 'sbfxd.sbtable' doesn't exist', Error_code: 1146
--17T03::.584268Z [Warning] Slave: Table 'sbfxd.sbtable' doesn't exist Error_code: 1146

(2)如果将主服务器的属性配错了需要stop slave,然后设置好之后start slave

Mysql5.7.13主从同步(复制)配置的更多相关文章

  1. MySQL数据库的主从同步复制配置

    一.主从同步机制原理 MYSQL主从同步是在MySQL主从复制(Master-Slave Replication)基础上实现的,通过设置在Master MySQL上的binlog(使其处于打开状态), ...

  2. 烂泥:mysql5.5主从同步复制配置

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在上篇文章<烂泥:学习mysql数据库主从同步复制原理>中,我们介绍了有关mysql主从复制的基本原理.在这篇文章中,我们来实际测试下mys ...

  3. mysql5.5主从同步复制配置

    在上篇文章<烂泥:学习mysql数据库主从同步复制原理>中,我们介绍了有关mysql主从复制的基本原理.在这篇文章中,我们来实际测试下mysql5.5的主从同步复制功能. 注意mysql5 ...

  4. percona-xtrabackup工具实现mysql5.6.34的主从同步复制

    percona-xtrabackup工具实现mysql5.6.34的主从同步复制 下载并安装percona-xtrabackup工具 # wget https://www.percona.com/do ...

  5. MySQL-5.6.13免安装版配置方法

    MySQL-5.6.13免安装版配置方法   1. 下载MySQL Community Server 5.6.13 2. 解压MySQL压缩包    将以下载的MySQL压缩包解压到自定义目录下,我的 ...

  6. Redis的主从同步复制

    先来看一下Redis的主从同步复制的原理: 在Slave启动并连接到Master之后,它将主动发送一条SYNC命令.此后Master将启动后台存盘进程,同时收集所有接收到的用于修改数据集的命令,在后台 ...

  7. mysql5.5 Replication 主从同步

    mysql5.5 Replication 主从同步 ------------------[主]------------------[mysqld]server-id=1 log-bin=mysql-b ...

  8. mysql 主从master-slave同步复制 配置,为读写分离准备

    1.为方便,我在一个windows下安装两个mysql实例,端口分别是 3306.3307 打开 my.ini 或 my-default.ini 文件 配置 basedir datadir 和port ...

  9. Mysql 半同步复制配置

    以下是配置和监控半同步复制: 1. 半同步复制功能以plugin的方式接入MySQL,需要在主库与从库两端同时开启半同步的支持,具体配置如下: On the master mysql> INST ...

随机推荐

  1. jQuery.zTree的跳坑记录

    最近项目用到树型结构的交互,一开始并不打算选择zTree,为了项目进度我妥协了,这一妥协后果就是我进坑了,在2天的挣扎中,我终于跳出坑了,活了下来,有一些感慨纪录下来. 有一个业务场景需要2个树型结构 ...

  2. ASCII和16进制对照表

    十六进制代码 MCS 字符或缩写 DEC 多国字符名 ASCII 控制字符 1 00 NUL 空字符 01 SOH 标题起始 (Ctrl/A) 02 STX 文本起始 (Ctrl/B) 03 ETX ...

  3. 匿名对象 构造方法 重载 构造代码块 this 关键字

    一.匿名对象 1.匿名对象 :没有名字对象 2.匿名对象的使用注意点: 1.我们一般不会用匿名对象给属性赋值,无法获取属性值. 2.匿名对象永远都不可能事一个对象. 3.匿名对象的好处 : 书写简单. ...

  4. linux下QT程序输出乱码解决方法

    参考文章:http://blog.csdn.net/jiang1013nan/article/details/6667871 http://my.oschina.net/zjlaobusi/blog/ ...

  5. c#List移除列表中的元素

    对于一个List<T>对象来说移除其中的元素是常用的功能.自己总结了一下,列出自己所知的几种方法. class Program { static void Main(string[] ar ...

  6. 线性分式变换(linear fractional transformation)

    线性分式变换(linear fractional transformation)的名称来源于其定义的形式:(ax+b)/(cx+d),其中分子分母是线性的,然后最外层是一个分式形式,所以叫做这个名字, ...

  7. 信号量sem

    一.什么是信号量 为了防止出现因多个程序同时访问一个共享资源而引发的一系列问题,我们需要一种方法,它可以通过生成并使用令牌来授权,在任一时刻只能有一个执行线程访问代码的临界区域.临界区域是指执行数据更 ...

  8. Android中数据存储(一)

    国庆没有给国家添堵,没有勾搭妹子,乖乖的写着自己的博客..... 本文将为大家介绍Android中数据存储的五种方式,数据存储可是非常重要的知识哦. 一,文件存储数据 ①在ROM存储数据 关于在ROM ...

  9. .net 文件上传大小的设置

    直接在配置文件web.config 中进行如下配置,主要需要明白的就是 配置的 单位是 Byte,  所以一定计算清楚,不然会在这里纠结很久!!! <configuration> < ...

  10. redis主从复制配置

    master配置 主要是下面配置 # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the # intern ...