• 【MySQL】使用xtrabackup创建mysql从库


    【MySQL】使用xtrabackup创建mysql从库

    1.master端备份

    xtrabackup --defaults-file=${mysql_cnf} --backup --user=${mysql_user} --password=${mysql_password} --target-dir=/path/to/backupdir

    2.prepare已经备份的数据

    xtrabackup --user=${mysql_user} --password=${mysql_password} --prepare --target-dir=/path/to/backupdir

    这样可以获得一个一致性的快照。事务日志被应用后,会创建一个新的日志。至此,数据文件就可以被mysql server使用了。

    3.将数据拷贝到slave节点

    使用rsync或者scp 如果使用rsync将数据数据同步到slave的数据目录,建议将slave的mysqd关闭

    rsync -avpP -e ssh /path/to/backupdir TheSlave:/path/to/mysql/

    4.将master的快照文件移动到指定的目录

    xtrabackup --move-back --target-dir=/path/to/mysql/backupdir

    修改属主

    chown mysql:mysql /path/to/mysql/datadir

    5.master创建复制用户

    grant replication slave on *.*  to 'repl'@'$slaveip'  identified by '$slavepass';

    6.配置slave

    拷贝master的配置文件

    scp user@TheMaster:/etc/mysql/my.cnf /etc/mysql/my.cnf

    编辑配置文件

    vi /etc/mysql/my.cnf
    server-id=2

    启动msql实例

    7.启动复制

    查看xtrabackup_info文件找到gtid

    reset master;
    reset slave;
    SET GLOBAL gtid_purged="515727a3-9379-11ec-9fb5-005056829fe8:1-63644";
    change master to master_host='$masterip', master_user='repl', master_password='$slavepass',master_port=3306,master_auto_position=1,master_connect_retry=10;
    start slave;
    show slave status\g

     

    增加更多的slave

    使用已经存在的slave,再创建一个slave。

    1.备份slave

    xtrabackup --backup --user=${mysql_user} --password=${mysql_password} --slave-info --target-dir=/path/to/backupdir

    参数--slave-info,会额外创建一个文件,叫做:xtrabackup_slave_info

    2.应用日志

    xtrabackup --prepare --use-memory=2G --target-dir=/path/to/backupdir/

    3.拷贝到新的从节点

    rsync -avprP -e ssh /path/to/backupdir TheNewSlave:/path/to/mysql/datadir

    4.主库创建复制用户

    grant replication slave on *.*  to 'repl'@'$newslaveip' identified by '$slavepass';

    5.拷贝配置文件

    scp user@TheSlave:/etc/mysql/my.cnf /etc/mysql/my.cnf

    6.修改配置文件

    vi /etc/mysql/my.cnf
    skip-slave-start
    server-id=3

    启动msql实例

    7.启动复制

    执行change master

    change master to master_host='$masterip', master_user='repl', master_password='$slavepass', master_port=3306,master_auto_position=1,master_connect_retry=10;
    start slave;

    注意点:

    1.innodb-log-file-size在出从两边设置要一样

    2.查看是否有memory引擎的表

    select concat('ALTER TABLE `',table_schema,'`.`',table_name,'` ENGINE=INNODB;')
    from information_schema.tables
    where engine='memory' and table_schema not in ('information_schema','performance_schema');
     
  • 相关阅读:
    【linux】linux根文件系统制作
    【linux】UBUNTU 12.04下傻瓜式简单安装arm-linux-gcc等gnu arm toolchain交叉编译工具
    【linux】内核编译
    【linux】内核源代码下载与阅读
    Jmeter实践
    常用sql 2018.08.31
    接口用例、实践参考
    UTF自动化测试工具
    MySql 中IFNULL、ISNULL、NULLIF用法(数据库判空)
    Mysql中FIND_IN_SET()和IN区别简析
  • 原文地址:https://www.cnblogs.com/abclife/p/16376228.html
Copyright © 2020-2023  润新知