dump many databases at once (using the option
? ? ? ? ? ? ? ? ? ? ?--databases= or --all-databases), the logs will be
? ? ? ? ? ? ? ? ? ? ?Locks all tables across all databases. This is achieved
? ? ? ? ? ? ? ? ? ? ?--all-databases or --databases is given.
?
?--master-data[=#] ? This causes the binary log position and filename to be
? ? ? ? ? ? ? ? ? ? ? appended to the output. If equal to 1, will print it as a
? ? ? ? ? ? ? ? ? ? ? CHANGE MASTER command; 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.
?
--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.
?
--include-master-host-port?
? ? ? ? ? ? ? ? ? ? ? Adds 'MASTER_HOST=
, MASTER_PORT=' to 'CHANGE
? ? ? ? ? ? ? ? ? ? ? MASTER TO..' in dump produced with --dump-slave.
?
?
--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.
? --set-charset ? ? ? Add 'SET NAMES default_character_set' to the output.
? ? ? ? ? ? ? ? ? ? ? (Defaults to on; use --skip-set-charset to disable.)
查看主从信息:
?
[root@WEBAPP_B_IP_HOST /data/backup/databases]#
?
自带切换主从同步点命令,需要注意的是添加此命令时需要将所有主从同步状态的
数据库数据一同导出。
grep CHANGE /data/backup/databases/hehehehhe20151109.sql?
CHANGE MASTER TO MASTER_LOG_FILE='
mysql-bin.000001', MASTER_LOG_POS=120;
?
2.数据导入:
?
?新机器:
?
CREATE DATABASE `hehehehhe` /*!40100 DEFAULT CHARACTER SET utf8 */;
?搭建主从同步后stop slave,直接通过mysql 直接导入数据,然后在start slave即可。
?
0x04 主从复制配置与数据的同步
?
1. MySQL binlog
?
binlog是MySQL主从复制的基础,MySQL通过binlog来记录
数据库数据的变更,可用来搭建主从复制集群,也可以用mysqlbinlog来通