mysql迁移检查清单

本清单旨在帮助DBA在迁移MySQL的时候,不要遗漏一些环节,以免造成数据不一致,保证迁移过程的平稳顺利。

为了保证数据一致性,迁移方案采用提前搭建主从+窗口期做主从切换的方式。

更新于 2021-10-12


[TOC]

前期准备

  • [DBA] 参考《利用audit审计日志》,梳理业务访问情况
  • [主库+从库] 启用binlog + server-id
  • [主库+从库] 参考《mysql主从常用操作》,搭建主从复制
  • [从库] 设置全局只读,并禁止自动清除relaylog(若采用mha架构)
set global read_only=on;
set global relay_log_purge=0;
  • [从库] 优化复制延迟,设置每x次事务提交及每x次relay事件刷新到磁盘
show variables like 'sync%log%';
set global sync_binlog=5000000;
set global sync_relay_log=5000000;
set global innodb_flush_log_at_trx_commit=0;
  • [从库] 利用pt-show-grants同步账号(若恢复的是整个实例则不需要)
select user,host,account_locked from mysql.user;
pt-show-grants -uroot -p -h192.168.64.128 -P3306
  • [主库] 确认是否存在事件、存储过程、触发器
SELECT db,name FROM mysql.event;
SELECT db,name,type FROM mysql.proc WHERE db NOT IN('mysql', 'information_schema', 'sys', 'performance_schema');
SELECT TRIGGER_SCHEMA,TRIGGER_NAME FROM information_schema.triggers WHERE TRIGGER_SCHEMA NOT IN('mysql', 'information_schema', 'sys', 'performance_schema');
  • [主库+从库] 比对 variables 变量
show variables where variable_name in ('log_bin','binlog_format','server_id','expire_logs_days','skip_name_resolve','gtid_mode','log_slave_updates','binlog_row_image','lower_case_table_names','collation_server','time_zone','sql_mode','innodb_strict_mode','tx_isolation');
  • [从库] 同步主库的云安全组+iptables防火墙到从库

维护窗口期

  • [运维] 停掉站点及任务
  • [老主库] 锁定账号,避免继续连接数据库(排除:root、dba_admin、dba_repl
select user,host,account_locked,case when account_locked = 'Y' then '已禁用' when account_locked = 'N' then '正常' end as account_locked_desc from mysql.user;
select concat('ALTER USER ','''',user,'''@''',host,'''',' ACCOUNT LOCK;') from mysql.user where account_locked='N' and user not in ('root','dba_admin','dba_repl') into outfile '/tmp/mysql_lock.sql';
select concat('ALTER USER ','''',user,'''@''',host,'''',' ACCOUNT UNLOCK;') from mysql.user where account_locked='N' and user not in ('root','dba_admin','dba_repl') into outfile '/tmp/mysql_unlock.sql';

# source /tmp/mysql_lock.sql;
# flush privileges;
  • [老主库] 杀掉所有用户连接(排除:root、dba_admin、dba_repl
select concat(group_concat('kill ', ID separator ';'),';') from information_schema.processlist where user not in ('root','dba_admin','dba_repl');
  • [老从库] 断开主从复制老从库变为新主库
stop slave;
reset slave;
  • [新主库] 取消只读
set global read_only=off;
  • [新主库] 新实例启用账号,可参考老主库上的备份命令:/tmp/mysql_unlock.sql
source /tmp/mysql_unlock.sql;
flush privileges;
  • [新主库] 抽样校验,方法包括:比对行数、核心表抽样比对内容;
  • [运维] 刷DNS或修改字符串
  • [新主库] 确认有新连接
show processlist;
  • [新主库] 启用高安全模式,设置每1次(最安全但性能损耗也最大)事务提交及每x次relay事件刷新到磁盘
set global sync_binlog=1;
set global sync_relay_log=1;
show variables like 'sync_%og';
  • [新主库] 调整参数,比如:innodb_buffer_pool_size等
  • [新主库] 启用event(若有)

后期工作

  • [DBA] 告知大数据团队(若有etl数据抽取任务)
  • [老主库] 做一次实例备份,然后异地归档
mysqldump --single-transaction --master-data=2 --flush-logs --triggers --events --routines -uroot -p -A -S /tmp/mysql_3306.sock > /data/alldb.20201012.sql
  • [老主库] 关闭mysql服务
mysqladmin -uroot -p -S /tmp/mysql_3306.sock shutdown
  • [新主库] 持续关注错误日志
tail -f /data/mysql_3306/error/mysql_run.err
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2022-01-14 17:30:05

results matching ""

    No results matching ""