MySQL复制-单个数据库与多个数据库,多个数据库或多个表

时间:2019-01-29 19:44:02

标签: mysql replication master-slave master slave

我在Mysql 5.6.27上进行复制时遇到一些问题。

最好在多个数据库之间拆分所有表,或者最好是使用单个数据库(内部具有很多表)(从复制的角度来看)?

例如,如果我在两个表之间拆分表(+-100个表,其中一些+5000万条记录)会有所帮助。 5个数据库还是没关系?

我的主人也有几个核心,每个核心都被大量使用(每个核心上使用+-80%的资源),但是在Slave上我具有类似的硬件,但仅使用了一个核心(+ -80%),另一个只能使用10%。

非常感谢您的任何建议 问候, S

2 个答案:

答案 0 :(得分:1)

在大多数情况下都没有关系。

MySQL默认情况下运行一个工作线程来重放复制事件。因此,在这种模式下,它将永远不会使用多个CPU内核。

有一个启用多个工作线程的选项,每个数据库中的更改都可以在这些线程中并行重放。但是线程可以独立运行,因此,如果您要求数据库彼此之间进行同步更新,则不应启用此选项。如果您要决定是否将表存储在单独的数据库中,那么我认为它们在逻辑上是相互关联的,并且应该保持同步更新。

出于某些其他原因,您可能选择将表存储在单独的数据库中:

  • 使备份和还原每个数据库中的所有表更加容易
  • 使对每个数据库中所有表的特权分配变得更容易
  • 允许同一表名存在于多个数据库中

但是关于查询性能或复制,使用多个数据库没有其他好处。它只是表和约束的一种命名空间。

答案 1 :(得分:0)

In regard to your CPU comment, this is actually normal (depending on the type of replication that you have setup). Typically what is replicated is not the "query" that you use, only the changes. For example on the Master server you run :

update users set city = 'New York' limit 100

What the Master does is find the 100 rows, then does the update ... this requires the CPU. The master (really simplified) sends to the Slave :

Change Row ID: 123 city = 'New York'
Change Row ID: 124 city = 'New York'
Change Row ID: 125 city = 'New York'
etc ... etc ...

So the Slave uses considerably less CPU since it's not "finding" the rows that need to be updated, but only updating the rows the Master has indicated with a key.