迁移数据到从库

数据导出:
mysqldump -uroot -p111111 -h127.0.0. -P3306 -q --single-transaction -R -E --triggers --default-character-set=utf8 -B db3306 > db3306.sql //单库备份
mysqldump -uroot -p111111 -h127.0.0. -P3306 -q --single-transaction -R -E --triggers --default-character-set=utf8 --all-databases> all.sql //全库备份 mysql -e "show databases;" -uroot -p111111 | grep -Ev "Database|information_schema|performance_schema|mysql" | xargs mysqldump -uroot -p111111 --databases {} > mysql_dump.sql
数据导入:
[root@mysql- mysql]# mysql -uroot -p111111 -h127.0.0. -P3307 < db3306.sql

配置GTID主从环境

编辑/etc/my.cnf,同时在master和slave上,添加如下内容:
log-bin =mysql-bin
binlog_format =row
log_slave_updates
gtid-mode =ON
enforce-gtid-consistency=ON

$ cat /etc/my.cnf

[mysql@mysql- ~]$ cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
port =
socket =/var/lib/mysql3306/mysql.sock [mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
user=root
password=
log=/var/log/multi.log [mysqld1]
server-id=
port =
datadir =/var/lib/mysql3306
socket =/var/lib/mysql3306/mysql.sock
pid-file = /tmp/mysqld1.pid
symbolic-links =
sql_mode =NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#配置GTID主从环境
log-bin =mysql-bin
binlog_format =row
log_slave_updates
gtid-mode =ON
enforce-gtid-consistency=ON [mysqld2]
server-id=
port =
datadir =/var/lib/mysql3307
socket =/var/lib/mysql3307/mysql.sock
pid-file = /tmp/mysqld2.pid
symbolic-links =
sql_mode =NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#配置GTID主从环境
log-bin =mysql-bin
binlog_format =row
log_slave_updates
gtid-mode =ON
enforce-gtid-consistency=ON [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

建立一个复制用户

登录主库:
mysql -uroot -p111111 -h127.0.0. -P3306
建立一个复制用户:
mysql>grant replication slave, replication client on *.* to repl@'localhost' identified by 'repl';
mysql>flush privileges;

从库配置命令

登录从库:
mysql -uroot -p111111 -h127.0.0. -P3307
> stop slave;
> change master to
master_host='localhost',
master_port=,
master_user='repl',
master_password='repl';
> start slave;

主库

mysql> show master status\G
*************************** . row ***************************
File: mysql-bin.
Position:
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: 2f76444d-171e-11e6-a99b-080027af21c4:-
row in set (0.00 sec) mysql> show processlist\G
*************************** . row ***************************
Id:
User: repl
Host: localhost:
db: NULL
Command: Binlog Dump GTID
Time:
State: Master has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
*************************** . row ***************************
Id:
User: root
Host: localhost:
db: db3306
Command: Query
Time:
State: init
Info: show processlist
rows in set (0.00 sec)

从库

mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysqld2-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 2f76444d-171e-11e6-a99b-080027af21c4
Master_Info_File: /var/lib/mysql3307/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 2f76444d-171e-11e6-a99b-080027af21c4:-
Executed_Gtid_Set: 2f76444d-171e-11e6-a99b-080027af21c4:-,
62daf5cb--11e6-a9c3-080027af21c4:
Auto_Position:
row in set (0.00 sec)

MySQL5.6 GTID方式,配置主从的更多相关文章

  1. docker创建mysql5.7.22并配置主从

    debian系统 安装docker (参考网址:https://cloud.tencent.com/developer/article/1360720) 1.更新现有的包列表 sudo apt upd ...

  2. MySQL5.7.15数据库配置主从服务器实现双机热备实例教程

    环境说明 程序在:Web服务器192.168.0.57上面 数据库在:MySQL服务器192.168.0.67上面 实现目的:增加一台MySQL备份服务器(192.168.0.68),做为MySQL服 ...

  3. centos7用docker安装mysql5.7.24后配置主从

    1)使用docker安装完成mysql5.7.24,我规划的是3台: 192.168.0.170(Master) 192.168.0.169(Slave) 192.168.0.168(Slave) 2 ...

  4. MySQL5.7主从同步--点位方式及GTID方式

    MySQL5.6加入了GTID的新特性,其全称是Global Transaction Identifier,可简化MySQL的主从切换以及Failover.GTID用于在binlog中唯一标识一个事务 ...

  5. centos6.6手动安装mysql5.5并配置主从同步

    0.实验环境 主机IP(Master) 192.168.61.150 centos6.6 从机IP(Slave)   192.168.61.157 centos6.6 1.查看centos系统版本 [ ...

  6. MySQL5.6 GTID新特性实践

    MySQL5.6 GTID新特性实践 GTID简介 搭建 实验一:如果slave所需要事务对应的GTID在master上已经被purge了 实验二:忽略purged的部分,强行同步 本文将简单介绍基于 ...

  7. percona-mysql5.7.24使用xtrabackup工具配置主从同步

    主从配置详细过程: 环境准备: 配置好服务器,主从服务器都安装并启动mysql数据库 # 添加读写账号和只读账号,应用配置中,写主库用读写账号,统计从库数据yoga只读账号 grant select, ...

  8. CentOS7下安装MySQL5.7安装与配置(转)

    原文地址:http://www.centoscn.com/mysql/2016/0626/7537.html 安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在M ...

  9. MySQL5.7安装与配置(YUM)

    安装环境:CentOS7 64位,MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/  # ...

随机推荐

  1. Python中的排序方法

    1 list.sort list.sort(key=None, reverse=False) 该方法只能用于list.就地排序,原来的list被修改.key的用法见下文.reverse控制降序还是生序 ...

  2. parsley.js验证的基本引用

    前段时间看到博客有些parsley.js验证,只是对parsley.js验证框架基本的应用,对parsley.js更深层理解没有介绍和demo 比如:异步请求,扩展验证的写法,我把我学到的parsle ...

  3. cstring replace

    //使用后将图纸名称存储到配置 换行符用^^替换 m_sTZMC.Replace(_T("\r\n"), _T("^^")); ini.SetValueOfKe ...

  4. Vue课程思维导图

  5. Spring框架系列(五)--面向切面AOP

    背景: 当需要为多个不具有继承关系的对象引入一个公共行为,例如日志.权限验证.事务等功能时,如果使用OOP,需要为每个对象引入这些公共 行为.会产生大量重复代码,并且不利用维护.AOP就是为了解决这个 ...

  6. [转]Js获取当前日期时间及其它操作

    转载自:http://www.cnblogs.com/carekee/articles/1678041.html Js获取当前日期时间及其它操作 var myDate = new Date();myD ...

  7. 手机端h5复制功能

    html: <a href="javascript:;" id="copyBtn" class="f-r tac" data-clip ...

  8. attack on titans(动态规划递推,限制条件,至少转至多方法,进击的巨人)

    题目意思: 给n个士兵排队,每个士兵三种G.R.P可选,求至少有m个连续G士兵,最多有k个连续R士兵的排列的种数. 原题 Attack on Titans Time Limit: 2 Seconds ...

  9. javaHashcode与equals

    转载自:http://blog.csdn.net/jiangwei0910410003/article/details/22739953 Java中的equals方法和hashCode方法是Objec ...

  10. 通过docker-composer启动容器nginx,并完成spring.boot的web站点端口转发

    前面已经讲过2篇基于docker的mysql.redis容器编排并启动.这次将练习下nginx的docker方式的部署,以及通过nginx去代理宿主主机上的Web服务应该怎么配 PS:(这里由于ngi ...