Mysql主日志pos在全局锁期间发生变化?

发布于 2024-09-24 02:14:45 字数 1458 浏览 2 评论 0原文

我必须设置一个新的 mysql 复制来复制两个数据库。所以我有这个脚本来锁定表,进行转储并解锁它们。

runme.sh

mysql -uxxx -pxxx < 1.sql >> logpos.txt
mysqldump -uXXX -pXXX db1 > db1.sql
mysqldump -uXXX -pXXX db2 > db2.sql
mysql -uxxx -pxxx < 2.sql >> logpos.txt

第一个 sql 文件锁定表并导出主状态:

1.sql

FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

第二个文件导出主状态并解锁表

2.sql

SHOW MASTER STATUS;
UNLOCK TABLES;

结果如下所示:

logpos.txt

File    Position        Binlog_Do_DB    Binlog_Ignore_DB
mysql-bin.000335        49106285        fli_search,flimmit
File    Position        Binlog_Do_DB    Binlog_Ignore_DB
mysql-bin.000335        49139991        fli_search,flimmit

问题: 当表被锁定时,日志位置如何改变?

Server version:  5.0.51a-24+lenny4-log (Debian)

我可以为多个数据库执行 mysqldump 并添加 --master-data,但我不知何故感到不安全,因为涉及不同的数据库格式,而且我无法真正找出 mysqldump --master-data 在多个数据库中的行为方式。所以我有这个脚本并得到了不同的日志位置......知道为什么吗?我无法使用它来设置复制...

更新:

我最终决定使用 mysqldump --master-data --databases db1 db2 设置复制 该转储是今晚凌晨 1 点创建的。 今天上午 10 点左右,我设置了奴隶。我完全清除了数据库(删除了所有表)并导入了转储,这会自动正确设置主日志文件和日志位置。我检查了它与 sql 转储中的相同。一切看起来都很好。 当然,我在导入之前停止了从属设备(否则我无法通过将 master 更改为语句来导入转储)。 我启动了奴隶,一切看起来都很好。 log pos 增加,master 落后的秒数减少并变为 0,并且一些测试数据被正确复制。

但今天上午 7 点左右(转储创建和导入之间的时间窗口)的重大更新却缺失了。它从表中删除了旧记录,在奴隶身上它们仍然存在...... 知道为什么吗?

需要任何其他信息吗?评论...

I have to set up a new mysql replication replicating two databases. So I have this script which locks tables, makes a dump and unlocks them.

runme.sh

mysql -uxxx -pxxx < 1.sql >> logpos.txt
mysqldump -uXXX -pXXX db1 > db1.sql
mysqldump -uXXX -pXXX db2 > db2.sql
mysql -uxxx -pxxx < 2.sql >> logpos.txt

first sql file locks tables and exports master status:

1.sql

FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

second file exports master status and unlocks tables

2.sql

SHOW MASTER STATUS;
UNLOCK TABLES;

the result looks like this:

logpos.txt

File    Position        Binlog_Do_DB    Binlog_Ignore_DB
mysql-bin.000335        49106285        fli_search,flimmit
File    Position        Binlog_Do_DB    Binlog_Ignore_DB
mysql-bin.000335        49139991        fli_search,flimmit

Question:
How can the log position change while tables are locked?

Server version:  5.0.51a-24+lenny4-log (Debian)

I could do mysqldump for multiple databases and add --master-data, but I somehow felt unsafe because there are different database formats involved and I couldn't really find out how mysqldump --master-data behaves with multiple databases. So I had this script and got different log positions.... any idea why? I cannot use this to set up a replication...

UPDATE:

I finally decided to set up replication with mysqldump --master-data --databases db1 db2
the dump was created tonight at 1 am.
today at about 10 am i set up the slave. i totally cleared the databases (dropped all tables) and imported the dump, which automatically set the master log file and log pos correctly. i checked that its the same as in the sql dump. everything looked fine.
of course i stopped the slave before importing (otherwise i couldnt import the dump with change master to statement anway).
i started the slave and eveyrthing looked just fine. the log pos increased, the seconds behind master decreased and went to 0 and some test data was replicated correctly.

but a major update from today ~7am (the time window between the dump creation and importing) was just missing. it pruned old records from a table, on the slave they were still present...
any idea why?

any additional information needeD? comment...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幼儿园老大 2024-10-01 02:14:45

如果您想查看在这两个位置值之间写入二进制日志的内容,您可以使用 mysqlbinlog 工具,将相关二进制日志条目转换为SQL。只需使用第一个 pos 作为开始位置,第二个 pos + 1 作为停止位置。这样您将看到 FLUSH 之后发生的所有事件(它还会显示刷新之前发生的最后一个事件,因此只需忽略第一个事件)。

使用你的例子:

mysqlbinlog --start-position=49106286 --stop-position=49139992 mysql-bin.000335

If you want to see what was written to the binary log during between those two position values, you can use the mysqlbinlog tool to convert the relevant binary log entries to SQL. Just use the first pos as the start-position and the second pos + 1 as the stop-position. That way you will see all events that happened after your FLUSH (it will also show you the last event that happened before the flush, so just ignore the first event).

Using your example:

mysqlbinlog --start-position=49106286 --stop-position=49139992 mysql-bin.000335
歌入人心 2024-10-01 02:14:45

看起来我也必须这样做:

FLUSH TABLES WITH WRITE LOCK;

主数据开关似乎不可靠......

looks like i also have to do:

FLUSH TABLES WITH WRITE LOCK;

the master data switch seems to be unrelyable...

知足的幸福 2024-10-01 02:14:45

您看到更改的原因是第一个脚本退出后锁就会被释放。从 手册

警告 - 让发出 FLUSH TABLES 语句的客户端保持运行状态,以便读锁保持有效。如果退出客户端,锁就会被释放。

The reason you saw changes is the lock is released as soon as the first script exits. From the manual:

Warning - Leave the client from which you issued the FLUSH TABLES statement running so that the read lock remains in effect. If you exit the client, the lock is released.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文