mysql slave创建:mysqldump参数--master-data

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/soonfly/article/details/73303049

在创建mysql从库时,通常我们先从主库dump下一份sql文件,再到mysql从库导入生成表,然后调用change master to开启从库,这时需要确定binlog文件和position位置。
那么如何确定position位置呢?

上网一搜,很多文章告诉你先到master库show master status查看postion。可是当你利用mysqldump导出主库,再到用show master status查看postion这段时间之间,master库早已变化了,这意味着postion位置也变化了。
准备的做法是从主库dump文件时,利用–master-data参数输出postion

官方文档地址:
https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

mysqldump –help解释:
–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.
示例:

mysqldump -uroot -ptwm123 --master-data=1  huiyedb > /data/bak/dumpfile

这里写图片描述

猜你喜欢

转载自blog.csdn.net/soonfly/article/details/73303049
今日推荐