MySQL 5.6到MySQL 8的主從複制

 行業動态     |      2022-04-23 21:01:31
MySQL 8與MySQL 5.6跨了兩個大版本,直接從5.6(主)複制到8(從)是不行的,因此需要用(yòng)一個MySQL 5.7版本作(zuò)為(wèi)橋接。5.6、5.7實例都要開啓log_bin和log_slave_updates。5.6、5.7、8的安(ān)裝(zhuāng)步驟從略。
 
1. 在5.7創建要複制的庫表,表使用(yòng)blackhole引擎
 
create database space;
use space;
create table space_praise_record (
  userid bigint(20) not null default '0' comment '用(yòng)戶id',
  objectid bigint(20) not null default '0' comment '對象id,作(zuò)品id或者分(fēn)享id',
  type smallint(6) not null default '0' comment '0 作(zuò)品; 1 分(fēn)享',
  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中(zhōng)創建要複制的表,表使用(yòng)缺省的innodb引擎
 
use spacex;
create table space_praise_record (
  userid bigint(20) not null default '0' comment '用(yòng)戶id',
  objectid bigint(20) not null default '0' comment '對象id,作(zuò)品id或者分(fēn)享id',
  type smallint(6) not null default '0' comment '0 作(zuò)品; 1 分(fēn)享',
  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
————————————————
版權聲明:本文(wén)為(wèi)CSDN博主「wzy0623」的原創文(wén)章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文(wén)出處鏈接及本聲明。
原文(wén)鏈接:https://blog.csdn.net/wzy0623/article/details/118605134