mysql slave创建:mysqldump参数--master-data
Posted 唐大麦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql slave创建:mysqldump参数--master-data相关的知识,希望对你有一定的参考价值。
在创建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
以上是关于mysql slave创建:mysqldump参数--master-data的主要内容,如果未能解决你的问题,请参考以下文章