主从同步是分布式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. Python爬虫学习(9):Selenium的使用

    1 简介以及安装 Selenium 是什么?一句话,自动化测试工具.它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏览器,如果你在这些浏览器里面安装一个 Seleni ...

  2. R语言绘制空间热力图

    先上图 R语言的REmap包拥有非常强大的空间热力图以及空间迁移图功能,里面内置了国内外诸多城市坐标数据,使用起来方便快捷. 开始 首先安装相关包 install_packages("dev ...

  3. Linux tricks

    Environment Settings Path Globally set path is in /etc/profile; or the user's .bash_profile for part ...

  4. .net core 产品开发问题记录

    背景 最近在公司的一个产品研发中,最终还是选择了以.net core 作为主要的技术方案.本文会拟记录开发过程中于以往中区别比较大,或者可能造成的坑. 程序集无法引用本地程序集 .net core 的 ...

  5. VS2015 调试时 编辑并继续不可用

    最近在项目中遇到一次调试时 编辑并继续不可用.结合网上说的工具->设置->调试->常规下的一些操作,到后来还是不可用,最后把项目的解决方案平台改成Mixed Platform ,之后 ...

  6. jade模板引擎

    最近用jade写了点东西,觉得挺有趣的,是一个有意思的模板引擎. 比如说,像这样的结构的html <span> <i class="icon-edit">& ...

  7. redis 下载及使用

    redis 官网下载地址:http://redis.io/ E:\工作软件\新建文件夹\redis64-2.8.19  redis-server.exe 执行该命令 当前已启动  端口号:6379 r ...

  8. Erlang error handling

    Erlang error handling Contents Preface try-catch Process link Erlang-way error handling OTP supervis ...

  9. 一个简单的路由,用javascript实现

    前端路由在很多开源的js类库框架中都得到支持,如angularJS,Backbone,Reactjs等等.前端路由和后端路由原理一样,是让所有的交互和展现在一个页面运行以达到减少服务器请求,提高客户体 ...

  10. Odoo 二次开发教程(二)-模块的基础构建

    注:本篇及后续均以8.0为基础. 一. Odoo模块的构成 __init__.py 文件是python包导入所必须的文件,内容可以为空,通常情况下我们用来导入自己写的py文件. __openerp__ ...