数据库
首页 > 数据库> > MySQL:Binlog保留多长时间?

MySQL:Binlog保留多长时间?

作者:互联网

我有一个mysql从属服务器,正在尝试复制一个主mysql实例.

我一周左右从生产主实例迁移数据.当时我在主机上调用了SHOW MASTER STATUS,并获得了binlog的名称和位置.现在,当我运行SHOW MASTER STATUS时,我得到:

mysql> SHOW MASTER STATUS;
+----------------------------+----------+--------------+------------------+-------------------+
| File                       | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------------+----------+--------------+------------------+-------------------+
| mysql-bin-changelog.039446 |      120 |              |                  |                   |
+----------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.05 sec)

那个二进制日志不同于一周前的二进制日志.

我可以不再开始复制b / c我要定位的binlog了吗?我可以签出变量以查看是否“拥有”了多久之后才能不再开始复制吗?

编辑:

还通过mysql文档进行了更多阅读,我发现了应该列出所有二进制日志的命令:

mysql> SHOW BINARY LOGS;
+----------------------------+-----------+
| Log_name                   | File_size |
+----------------------------+-----------+
| mysql-bin-changelog.039456 |       479 |
| mysql-bin-changelog.039457 |       120 |
+----------------------------+-----------+
2 rows in set (0.07 sec)

同样,我上周写下的二进制日志未在此处列出,因此我的问题仍然存在.

编辑2:

这是特定于AWS RDS的,但是我发现了一个存储过程,其中列出了保留时间:

mysql> call mysql.rds_show_configuration;
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| name                   | value | description                                                                                          |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| binlog retention hours | NULL  | binlog retention hours specifies the duration in hours before binary logs are automatically deleted. |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
1 row in set (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

Here它说binglog被保留24小时.我要复制的数据库需要24个小时以上的时间才能迁移,这意味着在准备复制时,它需要访问的复制日志已被删除…

编辑3:

找到here

Log File Size

The MySQL slow query log, error log, and the general log file sizes
are constrained to no more than 2% of the allocated storage space for
a DB instance. To maintain this threshold, logs are automatically
rotated every hour and log files older than 24 hours are removed. If
the combined log file size exceeds the threshold after removing old
log files, then the largest log files are deleted until the log file
size no longer exceeds the threshold.

解决方法:

对于特定于AWS RDS的实例,您可以使用以下存储过程找到二进制日志的保留长度:

mysql> call mysql.rds_show_configuration;
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| name                   | value | description                                                                                          |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| binlog retention hours | NULL  | binlog retention hours specifies the duration in hours before binary logs are automatically deleted. |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
1 row in set (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

在尝试将当前的MySQL RDS实例迁移到Amazon Aurora时,我必须首先迁移数据库,然后开始复制迁移窗口期间发生的任何更新.因为迁移需要24个小时,所以我需要设置一个比Amazon提供的默认24窗口更长的窗口,显然我可以使用以下stored procedure进行操作:

Amazon RDS normally purges a binary log as soon as possible, but the
binary log must still be available on the instance to be accessed by
mysqlbinlog. To specify the number of hours for RDS to retain binary
logs, use the mysql.rds_set_configuration stored procedure and specify
a period with enough time for you to download the logs. After you set
the retention period, monitor storage usage for the DB instance to
ensure that the retained binary logs do not take up too much storage.

This example sets the retention period to 1 day:

call mysql.rds_set_configuration('binlog retention hours', 24);

看起来我需要增加主服务器上的保留时间并进行另一次迁移,因此我的当前迁移无法再正确地进行复制.

标签:amazon-web-services,amazon-rds,amazon-rds-aurora,mysql
来源: https://codeday.me/bug/20191028/1949091.html