History 2

MySQL 5.7主从复制

*爱你&永不变心* 提交于 2021-02-16 11:37:29
https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html GTID(GlobalTransaction ID)是对于一个已提交事务的编号,并且是一个全局唯一的编号。GTID实际上是由UUID+TID组成的。其中UUID是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增。 设置gtid模式,在my.cnf里面的mysqld选项卡里面设置,设置完后,重启mysql服务生效: [mysqld] gtid_mode=ON log-slave-updates=ON enforce-gtid-consistency=ON mysql> change master to master_host=‘主库IP', master_port=主库端口, master_user='repl', master_password=‘repl密码', master_auto_position=1 ; mysql> start slave; PS:其中这里有差别,以前非gtid的是用master_log_file='mysql-bin.000009',master_log_pos=154;而gtid就采用了master_auto_positon=1;来自动同步主库的binlog了。

【业务系列】面对大表的归档处理

无人久伴 提交于 2020-03-26 23:25:12
3 月,跳不动了?>>> 可以搞个存储过程: create table history_tmp like history; maxid=select max(id) from history; minid=select id from history where addtime>"2013-01-01 00:00" order by addtime asc limit 1; last=0; set autocommit=1; for(i=minid;i<maxid+1000;i+=1000) { insert into history_tmp select * from history where id>=last and id<i lock in share mode; last=i; } begin; lock table history_tmp write,history write; maxid=select max(id) from history; insert into history_tmp select * from history where id>=last and id<=maxid; alter table history rename to history_2012; alter table history_tmp rename to history;