简体   繁体   English

Mysql存储引擎用于日志表

[英]Mysql storage engine for log table

What is the best storage engine to use for a log table on mysql? 在mysql上使用日志表的最佳存储引擎是什么?

The table will have a couple if id fields (ints) a date field, a varchar for the message level and a text field with the message. 该表将有一对if字段(int),一个日期字段,一个用于消息级别的varchar和一个带有该消息的文本字段。

It will log all sort of things, user actions, system events etc.. It is expected to grow huge quickly. 它将记录所有类型的事物,用户操作,系统事件等。预计它会迅速增长。

Records in it will never be modified and rarely accessed. 其中的记录永远不会被修改,很少被访问。 When accessed the should be sortable by date level and id. 访问时,应按日期级别和ID进行排序。

An interesting option is the archive engine. 一个有趣的选项是归档引擎。 It meets all criteria but has one big drawback, not only can't records be deleted, the table can't even be purged. 它符合所有标准,但有一个很大的缺点,不仅不能删除记录,甚至不能清除表。 The only way to clear the table is to delete it and recreate it. 清除表的唯一方法是删除它并重新创建它。

Any suggestions? 有什么建议?

Well, according to your question, InnoDB should do the work because: 那么,根据你的问题,InnoDB应该做的工作是因为:

  1. It's scalability is a lot better than MyISAM 它的可扩展性比MyISAM好很多
  2. It's row-locking, therefore if you are going to have more writes than selects, it fits better. 它是行锁定的,因此如果你要有更多的写入而不是选择,那么它更适合。
  3. Finally, since you said that they will be rarely accessed, there is no need for MyISAM since it is better on select queries. 最后,由于您说他们很少被访问,因此不需要MyISAM,因为它对选择查询更好。

Check this for more information 请查看此以获取更多信息

EDIT 编辑

Well, in the comment you ask about other engines. 那么,你在评论中询问其他引擎。 Here is a full list of engines. 这是一个完整的引擎列表 Among them, as you said archive has a disadvantage, the others do not fit to your request. 其中,如你所说存档有缺点,其他不适合你的要求。 Here is a quotation from MySQL website: 这是来自MySQL网站的报价:

InnoDB has been designed for maximum performance when processing large data volumes. 
Its CPU efficiency is probably not matched by any other disk-based relational database
engine.

So basically: 所以基本上:

  1. If you're going to use MEMORY don't as you said you won't access data a lot and your table will grow too much. 如果您打算使用MEMORY,请不要像您说的那样,不会大量访问数据,而且您的桌子会增长太多。 You will need a lot of RAM for that and when you reboot all data will be lost. 您将需要大量的RAM,当您重新启动时,所有数据都将丢失。
  2. If you're going to use MyISAM don't as it is designed for tables which select queries are more frequent than insert and update. 如果您打算使用MyISAM,请不要将其设计用于选择查询的表比插入和更新更频繁。
  3. As for archive, that's your choice. 至于存档,这是你的选择。 Here is a comparison between MyISAM and archive for a log table. 以下是MyISAM和日志表存档之间的比较。 I would stick to InnoDB though. 我会坚持InnoDB。
  4. I won't even mention Merge, Blackhole, Example and other engines. 我甚至不会提到Merge,Blackhole,Example和其他引擎。 (I don't have much knowledge on CSV engine but as far as I've read, that is a not an approriate engine for this kind of table. (我对CSV引擎知之甚少,但据我所知,这对于这种表来说并不是一个合适的引擎。

To be honest, I used to spend a lot of time before making an important move in coding. 说实话,我曾经花了很多时间才开始编码。 I researched for hours, maybe for days about an issue to see which way is the most appropriate. 我研究了几个小时,也许是几天关于一个问题,看看哪种方式最合适。 I'll tell you what, researching is good, but after a point if it prevents you from working then you should stop, drink a coffee, and make your choice right away. 我会告诉你什么,研究是好的,但是在一点之后,如果它阻止你工作,那么你应该停下来,喝一杯咖啡,然后马上做出选择。 Therefore, just try the most appropriate one to you and as you will experience you will find even a better way, by trying yourself. 因此,只要尝试最合适的一个,就像你将体验到的那样,通过自己尝试,你会发现更好的方法。 I mean, I don't believe that Facebook was designed for such a volume, but as it grew, they continued to change the structure accordingly. 我的意思是,我不相信Facebook是为这样的音量设计的,但随着它的发展,它们继续相应地改变结构。 That's what I believe though, may not be the reality :) Anyways, hope that info helps you. 这就是我所相信的,可能不是现实:)无论如何,希望信息可以帮助你。

EDIT 2013 编辑2013

Below you'll find brief descriptions for built-in MySQL storage engines. 您将在下面找到内置MySQL存储引擎的简要说明。

MyISAM MyISAM数据

These tables include additional optimizations, such as advanced cache and indexing mechanisms, which provide fast access to data. 这些表包括其他优化,例如高级缓存和索引机制,可以快速访问数据。 Using table-level locking, the MyISAM storage engine provides for concurrent operations. 使用表级锁定,MyISAM存储引擎提供并发操作。 When read performance is a concern, generally, MyISAM is the choice. 当阅读性能受到关注时,通常,MyISAM是您的选择。

Memory 记忆

Also called heap tables, memory tables are ideal for fast retrievel of frequently used data that is rarely altered (such as country codes, zip codes or other lookup tables). 内存表也称为堆表,非常适合快速检索很少更改的常用数据(例如国家/地区代码,邮政编码或其他查找表)。 As the name suggests, data is stored in memory and hence access is much faster than data stored in disks. 顾名思义,数据存储在内存中,因此访问速度比存储在磁盘中的数据快得多。 One significant restriction for using memory is that data is valid during MySQL session. 使用内存的一个重要限制是数据在MySQL会话期间有效。 When it crashes, or shuts down data is lost. 当它崩溃或关闭时数据丢失。

InnoDB InnoDB的

One case where you will have to use this storage engine is when you need to use foreign keys or transactions. 当您需要使用外键或事务时,必须使用此存储引擎的一种情况。 InnoDB is more concurrent than MyISAM since it provides row-level locking. InnoDB比MyISAM更并发,因为它提供行级锁定。 The storage engine is highly reliable. 存储引擎非常可靠。 Another case when you will want to use this storage is when you have more writes than reads. 当您想要使用此存储时,另一种情况是您有更多写入而不是读取。 When you frequently write data into the table try using this storage is it is more concurrent than MyISAM. 当您经常将数据写入表中时尝试使用此存储,它比MyISAM更并发。

Archive 档案

It is designed for storing large amounts of data in a compressed format. 它旨在以压缩格式存储大量数据。 One of the use cases of this storage engine is to store archival or historical data or security logs. 此存储引擎的一个用例是存储归档或历史数据或安全日志。 The table uses no indexes so for daily data retrieval and storage it is not a good choice. 该表不使用索引,因此对于日常数据检索和存储而言,它不是一个好的选择。 It's row-level locking and data is uncompressed on the fly when demanded. 它是行级锁定,数据在需要时即时解压缩。 Moreover, altering the table is not possible. 而且,改变桌子是不可能的。

Merge 合并

Merge is used to 'merge' partitioned tables which reside on the same machine. 合并用于“合并”驻留在同一台计算机上的分区表。 When you split a large table into several smaller tables, and access them simultaneously using a merge-table, the biggest benefit is its speed. 将大表拆分为多个较小的表并使用合并表同时访问它们时,最大的好处是它的速度。 Searches and sorts will execure quicker since there is less data in tables. 由于表中的数据较少,因此搜索和排序会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM