简体   繁体   English

用于PHP会话存储的最佳MySQL存储引擎

[英]Best MySQL storage engine to use for PHP session storage

I want to use MySQL to store session variables. 我想使用MySQL来存储会话变量。 From what I understand this means that on every page request there will be one read and one write to the table. 根据我的理解,这意味着在每个页面请求中将有一个读取和一个写入表。

Which MySQL storage engine is best suited for this task? 哪个MySQL存储引擎最适合此任务? MyISAM, InnoDB , MariaDB (which I don't see in PHPMyAdmin), Memory, or something else entirely? MyISAM,InnoDB,MariaDB(我在PHPMyAdmin中没有看到),内存还是完全不同的东西?

"Best" means nothing. “最好”意味着什么。 You need to express your constraints: do you need consistency? 你需要表达你的约束:你需要一致性吗? Durability? 耐用性? High-availability? 高可用性? Performance? 性能? A combination of all these properties? 所有这些属性的组合? Can you afford to loose your sessions? 你能负担得起你的会议吗? Can they fit in memory? 他们能适应记忆吗? Do you need to support concurrent accesses to the same data? 您是否需要支持对同一数据的并发访问?

Without more context, I would choose InnoDB which is the most balanced storage engine. 没有更多的上下文,我会选择InnoDB,这是最平衡的存储引擎。 It provides correct performance for OLTP applications, ACID transactions, good reliability, and sensible concurrency management. 它为OLTP应用程序,ACID事务,良好的可靠性和合理的并发管理提供了正确的性能。 Session variables access will likely be done using primary keys, and this operation is very efficient with InnoDB. 会话变量访问可能会使用主键完成,而此操作对InnoDB非常有效。

Now if performance is really a constraint, I would rather use a NoSQL engine (ie not MySQL). 现在,如果性能确实是一个约束,我宁愿使用NoSQL引擎(即不是MySQL)。 To store session data, Redis usually does a very good job, and is easy enough to integrate and deploy. 为了存储会话数据, Redis通常做得非常好,并且很容易集成和部署。

Memory storage engine sounds to be the best option. 内存存储引擎听起来是最好的选择。 Keep in mind that this is good for temporary sessions. 请记住,这对临时会话很有用。

http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html

It depends on how you evaluate "betterness": 这取决于你如何评价“更好”:

MyISAM is the most common (many shared hosting packages only let you use MyISAM). MyISAM是最常见的(许多共享主机包只允许您使用MyISAM)。 plus it is rather limited in the relationship control aspect, so you set it up really fast and easy. 加上它在关系控制方面相当有限,因此您可以非常快速和轻松地进行设置。 if you want portability and fast implementation across multiple hosting scenarios, MYISAM IS BEST. 如果您希望在多个主机方案中实现可移植性和快速实施,MYISAM是最佳选择。

InnoDB allows you to create relationships and saveguard data integrity by linking keys in different tables, which means more work but much more professional db design. InnoDB允许您通过链接不同表中的键来创建关系并保护数据完整性,这意味着更多的工作,但更专业的数据库设计。 many shared hosting packages do not implement InnoDB, therefore when exporting table structure from one environment to another, you might have some extra work to do. 许多共享主机包不实现InnoDB,因此在将表结构从一个环境导出到另一个环境时,您可能需要做一些额外的工作。 if you want realationship management and control, INNODB IS BEST. 如果你想要管理和控制,INNODB是最好的。

As far as data portability is concerned, an InnoDB database will be completely accepted by MyISAM (because MyISAM does not check data integrity: "is there a user number 4 in the user database when i insert a new record in user_car, for example"). 就数据可移植性而言,MyISAM将完全接受InnoDB数据库(因为MyISAM不检查数据完整性:“当我在user_car中插入新记录时,用户数据库中是否有用户编号4,例如”) 。 If you start out with MyISAM, exporting to a full-fledged InnoDB database will be a nightmare, even if your data has all keys, table data must be imported in the correct order (user and car, before user_car). 如果你从MyISAM开始,导出到一个成熟的InnoDB数据库将是一场噩梦,即使你的数据有所有键,表数据必须以正确的顺序导入(用户和汽车,在user_car之前)。

MariaDB? MariaDB的? never, simply because less people use it, therefore you will have less support, as compared to MyISAM and InnoDB. 从来没有,因为较少的人使用它,因此与MyISAM和InnoDB相比,你将获得更少的支持。

Bottom line clincher: INNODB. 最重要的是:INNODB。

If you do not wan't the overhead from a SQL connection consider using MemCached session sorage. 如果您不希望SQL连接的开销考虑使用MemCached会话搜索。 See http://php.net/manual/en/memcached.sessions.php http://php.net/manual/en/memcached.sessions.php

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

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