Py学习  »  DATABASE

MySQL 5.6到MySQL 8的主从复制

PHP开源社区 • 2 年前 • 232 次点击  
阅读 24

MySQL 5.6到MySQL 8的主从复制

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 to master_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 to master_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

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