• mysql 5.7 迁移数据方案


    从一台服务器迁移至其他服务器,如何选择最短的停服时间方案

    方案一、凌晨3点的全备份+停服后一天的大概一天的增备

      1. 拷贝前一天的全备份至新的服务器

       rsync -auzrP /Data/dbbak/db/2019-04-23/2019-04-23_03-10-11 root@172.16.1.80:/data/backup/full/

      2. 解压(备份方式:innobackupex  --compress,所以需要提前解压)

       innobackupex --decompress /data/backup/full/2019-04-23_03-10-11

      3. 停服

       systemctl stop mysqld

      5. 增备

       innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456  --incremental /data/backup/incr --incremental-basedir=/data/backup/full/2019-04-02_16-42-43

      6. 恢复

      --应用日志

       innobackupex --defaults-file=/usr/local/mysql/etc/my.cnf --apply-log --redo-only  /data/2019-04-18_03-10-09/

       innobackupex --defaults-file=/usr/local/mysql/etc/my.cnf --apply-log --redo-only  /data/2019-04-18_03-10-09/  --incremental-dir=/root/2019-04-18_19-06-43

       7. 拷贝至data目录下,并授权

       innobackupex --defaults-file=/usr/local/mysql/etc/my.cnf --copy-back /data/2019-04-18_03-10-09/

       chown -R  mysql:mysql /data/mysql-data/

       chmod -R 755   /data/mysql-data/

      8. 恢复完成,启动mysql

      mysqld_safe  --user=mysql &

    方案二、当前时间全备+binglog恢复

      1. 全备份(热备,物理备)

      innobackupex --defaults-file=/etc/my.cnf --user=root --password='123456'  --use-memory=12G --kill-long-queries-timeout=5 --ftwrl-wait-timeout=20 --compress  --compress-threads=16 /data/bak/db/`date +%F`

      2. 拷贝至新服务器,并恢复

       rsync -auzrP /Data/dbbak/db/2019-04-23/2019-04-23_03-10-11 root@172.16.1.80:/data/backup/full/

       innobackupex --decompress /data/backup/full/2019-04-23_03-10-11

       innobackupex --apply-log  /data/backup/full/2019-04-23_03-10-11

       innobackupex --copy-back  /data/backup/full/2019-04-23_03-10-11

      3. 停服保证数据一致性,再将期间产生的binlog拷贝至新的服务器并执行

      mysqlbinlog --start-position=1108  mysql-bin.000007 |mysql -uroot -p123456 -v 

     方案三、主从架构复制的方式

      1.用全备份恢复

       rsync -auzrP /Data/dbbak/db/2019-04-23/2019-04-23_03-10-11 root@172.16.1.80:/data/backup/full/

       innobackupex --decompress /data/backup/full/2019-04-23_03-10-11

       innobackupex --apply-log  /data/backup/full/2019-04-23_03-10-11

       innobackupex --copy-back  /data/backup/full/2019-04-23_03-10-11

      2. 授权新服务器复制权限

      GRANT REPLICATION SLAVE ON *.* TO 'rep20'@'10.8.9.20' IDENTIFIED BY '123456';

      3. 给所有表加上只读锁

      flush tables with read lock;

      4. 配置主从

       stop slave;

       change master to master_host='172.16.1.88', master_user='rep20', master_password=' 123456', master_log_file='mysql-bin.000614',  master_log_pos=296235077;

       start slave;

      5. 查看主从状态

      Master_Log_File和Relay_Master_Log_File所指向的文件必须一致

      Relay_Log_Pos和Exec_Master_Log_Pos的为止也要一致才行

      Slave_SQL_Running_State:显示为wait 意思是中继日志的sql语句已经全部执行完毕

      6. 验证部分表的记录条数,和最后一条数据的内容

      select count(*) from student;

      select * from student order by create_time desc limit 1;

      7. 解锁

      UNLOCK TABLES;

      

    总结: 方案一是增备的方式,步骤复杂了一些,操作失误就得重新恢复,停服的时间也需要更长,出错的概率也相对大;

          方案二 停服前全备份(还是热备),真正停服的时间是拷贝binlog和恢复binlog的时间,速度快,2步骤,出错概率低;(推荐)

       方案三 停服时间最短,但是相对更难校验数据的一致性,一旦数据不一致还有写入,会造成很大的麻烦。

      

       

  • 相关阅读:
    Docker
    docker
    Go
    Docker4Windows -- 从外部(非本机host)访问 由docker container运行的程序
    Unable to resolve target 'android-9'
    win7中VS2010中安装CSS3.0问题解决方法
    修改vs2005,vs2008,vs2010调试默认浏览器
    Android SDK Content loader has encountered a problem” “parseSdkContent Failed ”
    解决parseSdkContent failed java.lang.NullPointerException错误
    50个Android开发人员必备UI效果源码[转载]
  • 原文地址:https://www.cnblogs.com/Jack1023/p/10905888.html
Copyright © 2020-2023  润新知