社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

MySQL 5.6到MySQL 8的主从复制

码小辫 • 4 年前 • 757 次点击  

码小辫
专注更多编程视频和电子书
天天在用钱

作者 | wzy0623     责编 | 晋兆雨

出品 | CSDN博客

MySQL 8与MySQL 5.6跨了两个大版本,直接从5.6(主)复制到8(从)是不行的,因此需要用一个MySQL 5.7版本作为桥接。5.6、5.7实例都要开启log_bin和log_slave_updates。5.6、5.7、8的安装步骤从略。

1. 在5.7创建要复制的库表,表使用blackhole引擎

create database space;use space;create table space_praise_record (  userid bigint(20) not null default '0' comment '用户id',  objectid bigint(20) not null default '0' comment '对象id,作品id或者分享id',  type smallint(6) not null default '0' comment '0 作品;1 分享',  createtime timestamp not null default current_timestamp,  status smallint(6) not null default '1' comment '状态 0 取消赞 1 未读点赞 2 已读点赞 ',  touserid bigint(20) not null default '-1',  primary key (userid,objectid,type),  key inx_to_userid (touserid,userid,status),  key inx_objectid (objectid,type,status,createtime),  key index_1 (touserid,status),  key inx_touserid_createtime (touserid,createtime)engine=blackhole default charset=utf8mb4 comment='点赞记录表';

2. 在8中创建要复制的表,表使用缺省的innodb引擎

use spacex;
create table space_praise_record (
userid bigint(20) not null default '0' comment '用户id',
objectid bigint(20) not null default '0' comment '对象id,作品id或者分享id',
type smallint(6) not null default '0' comment '0 作品;1 分享',
createtime timestamp not null default current_timestamp,
status smallint(6) not null default '1' comment '状态 0 取消赞 1 未读点赞 2 已读点赞 ',
touserid bigint(20) not null default '-1',
primary key (userid,objectid,type),
key inx_to_userid (touserid,userid,status),
key inx_objectid (objectid,type,status,createtime),
key index_1 (touserid,status),
key inx_touserid_createtime (touserid,createtime)
) comment='点赞记录表';

3. 在8启动到5.7的复制

stop slave;reset slave all; change master tomaster_host='10.10.10.1',master_port=3306,master_user='u1',master_password='123456',master_log_file='mysqlbinlog.000001',master_log_pos=120; change replication filter replicate_do_table = (spacex.space_praise_record), replicate_rewrite_db = ((space, spacex)); start slave;

4. 在5.7上配置到5.6的复制

stop slave;reset slave all; change master tomaster_host='10.10.10.2',master_port=3306,master_user='u1',master_password='123456'; change replication filter replicate_do_table = (space.space_praise_record);

5. 将5.6的表复制到5.7

mysqldump -u u1 -p123456 -S /data/3306/mysqldata/mysql.sock --no-create-info --quick --apply-slave-statements --single-transaction --master-data=1 space space_praise_record | mysql -u u1 -p123456 -h10.10.10.1 -P3306 -Dspace

声明:本文为 CSDN 博主「wzy0623 」的原创文章,版权归对方所有。

原文地址:https://wxy0327.blog.csdn.net/

-END-

关注视频号,参与留言送书活动

↓↓↓↓

一个认真分享的小编

前沿技术 /名企内推 /干货分享

商务合作:dot3721
长按左侧二维码添加

点分享

点点赞

点在看

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/117084
 
757 次点击