mysql在从库备份制作新从库

来源:互联网 发布:windows不能识别usb 编辑:程序博客网 时间:2024/06/01 18:20

在已经存在的主从结构中,如果想要新添加从库,可以在主库上dump出备份在制作新从库,也可以在之前的从库上做备份,使用从库的备份制作新从库。
/usr/local/mysql-5.7.18/bin/mysqldump -u root -S /my.sock -p–default-character-set=utf8 –single-transaction –include-master-host-port=true –dump-slave=2 baixyu>baixyu.sql

使用这个命令在制作备份的时候,从库上的同步会中断,在备份完成后,会继续正常同步。对于dump-slave的说明
–dump-slave[=#] This causes the binary log position and filename of the
master to be appended to the dumped data output. Setting
the value to 1, will printit as a CHANGE MASTER command
in the dumped data output; if equal to 2, that command
will be prefixed with a comment symbol. This option will
turn –lock-all-tables on, unless –single-transaction is
specified too (in which case a global read lock is only
taken a short time at the beginning of the dump - don’t
forget to read about –single-transaction below). In all
cases any action on logs will happen at the exact moment
of the dump.Option automatically turns –lock-tables off.

–single-transaction
Creates a consistent snapshot by dumping all tables in a
single transaction. Works ONLY for tables stored in
storage engines which support multiversioning (currently
only InnoDB does); the dump is NOT guaranteed to be
consistent for other storage engines. While a
–single-transaction dump is in process, to ensure a
valid dump file (correct table contents and binary log
position), no other connection should use the following
statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
TRUNCATE TABLE, as consistent snapshot is not isolated
from them. Option automatically turns off –lock-tables.