3

我有一个主 mysql 服务器和 2 个从属服务器作为备份。

其中一个奴隶配备了固态存储,因此大量用于报告。

生成的一些数据需要一些时间(在某些情况下大约半小时到一个小时)并使用和生成数据分配(大约几场演出,这让我对使用事务犹豫不决)。报告表只是整个数据库的一小部分,因此完全关闭复制在某种程度上是不可能的。

手头的问题是在生成数据时生成的报告显然不完整且错误。

  1. 在主服务器和报告服务器上锁定表的最佳方法是什么?
  2. 是否会将“LOCK TABLES”语句复制到从属服务器,或者我最好的做法是在临时表中生成数据,然后在一个 INSERT ... SELECT 语句中将它们复制到最终表中。
4

1 回答 1

2

Try the following

You could try the following:

Step 01) On the Master, run this

FLUSH TABLES WITH READ LOCK; SELECT CONNECTION_ID(); SELECT SLEEP(300);

Step 02) SHOW SLAVE STATUS\G on both Slaves (or just the Reporting Slave)

Step 03) Repeat Step 02 Until

  • Relay_Log_Space stops changing
  • Relay_Log_Pos stops changing
  • Seconds_Behind_Master is 0

At this point, since both Slaves have not received any new SQL to process, you have effectively frozen MySQL on the Slaves at the Same Point-In-Time as the Master

Step 04) On the Slaves (or just the Reporting Slave), run STOP SLAVE;

Step 05) On the Master, (if the CONNECTION_ID() return 789) run mysql> KILL 789; in another mysql session.

Step 06) Run your reports

Step 07) Run START SLAVE; on the Slaves (or just the Reporting Slave)

UPDATE 2012-06-05 15:15 EDT

Since this seems a little heavy handed for the sake of a few tables in one particular schema, the simplest thing would just be to run STOP SLAVE; on the Slave you do the Reporting from.

于 2012-06-05T16:56:35.250 回答