Home > Database > Mysql Tutorial > body text

MySQL的内存表在主从同步的注意事项_MySQL

WBOY
Release: 2016-06-01 13:51:24
Original
1005 people have browsed it

       有一些应用程序需要存放一些临时数据,这时候临时表似乎是一个很好的选择,但是内存表在主从数据库上表现却不那么好。

       原因很简单,无论是基于STATEMENT还是基于ROW复制,都要在二进制日志中包含改变的数据。这就要求在主从机上数据必须一致。当重启从库的时候,你就会丢失内存表的数据,复制中断。

      我们该怎么办呢?

1.使用Innodb表代替

innodb表非常快,能满足我们对性能的需求。

2.在复制中忽略内存表

如果不是非常有必要的话,忽略复制内存表,使用这个选项replicate-ignore-table=db.memory_table。我们需要注意的是:STATEMENT复制,不要使用insert ... select 添加数据到内存表。如果要使用insert ... select,从机上的表将会是空的,甚至某些时候,内存表根本不会复制到从机上。还有一种解决办法是在主从机上都部署上相同的计划任务,来刷新这个表。

3.谨慎重启从机

从长远角度考虑我不会使用内存表,作为解决方案。

翻译自:

http://www.mysqlperformanceblog.com/2010/10/15/replication-of-memory-heap-tables/

此外还有关于如果真在工作中使用了内存表,并且重启了从机上的MySQL,还想和主机上的MySQL保持数据同步的话,这里有一个解决方案。

http://forge.mysql.com/tools/tool.php?id=163

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!