在 MySQL 数据库中使用不同的表类型是一个好习惯吗?
我正在用 PHP 开发一个游戏,当然我需要创建大约 1000 个不同的表来存储各种类型的数据。我听说,如果我错了,请纠正我,InnoDB 对于需要大量更新的表来说更好,因为行锁定与 MyISAM 的表锁定相反。然而,MyISAM 的选择速度更快。
我的问题是,我应该只坚持使用一种桌子类型,还是根据桌子的需要混合搭配?
I am developing a game in PHP and of course there are about 1000 different tables I will need to create to store various types of data. I heard, correct me if I am wrong, that InnoDB is better for tables that will be updated a lot because of row locking opposed to MyISAM's table locking. However MyISAM is faster with selections.
My question is, should I just stick with one table type, or is it good to mix and match based on the needs of the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
混合一下就可以了。
MyISAM
对于某些查询速度更快,并且支持FULLTEXT
和SPATIAL
索引,而InnoDB
是事务性的且更具并发性。在我目前正在咨询的一个数据库项目中,存在用于这些目的的混合表。
It's OK to mix.
MyISAM
is faster for certain queries and supportsFULLTEXT
andSPATIAL
indexes, whileInnoDB
is transactional and more concurrent.In a database project I'm currently consulting there is a mix of tables for these very purposes.
这取决于您的要求。如果你需要行级锁定、外键约束等,你应该选择 InnoDB,但如果你不需要它,你可以选择 MyISAM。一般来说,InnoDB 在大多数情况下都是不错的选择,但没有什么可以阻止您为表选择多种类型的引擎,这就是 MySQL 的魅力。
It depends on your requirements. If you need row-level locking, foreign key constrains, etc you should go for InnoDB, but if you don't need it, you can go for MyISAM. Generally, InnoDB is way to go in most cases but nothing stops you from choosing multiple types of engines for your tables, that is beauty of MySQL.
是的,如果需要,您可以在同一个数据库中混合 MyISAM 和 InnoDB,没有任何问题
Yes you can mix MyISAM and InnoDB in same database if required without any problem
虽然你可以混合表,但我会完全坚持使用 InnoDB。虽然 MyISAM 对于某些查询可能更快,但如果调整得当,InnoDB 通常会更快。如果通过主键查询,InnoDB 会要求 MyISAM 加快速度,因为 InnoDB 按主键顺序存储数据。 MyISAM 对于二级索引可能更快。
MyISAM 不支持事务,如果您有 1000 个表,那么您很可能会在一个操作中更新多个表,并且所有这些更新都应该在事务内完成(或者准备好在并发性成为一个问题时面临重大麻烦)当您的游戏繁忙或数据库滞后时会出现问题!)。
坚持使用一种表类型还可以使数据库计算机上的内存管理更加容易。 InnoDB 使用专用 RAM 进行缓存,而 MyISAM 则依赖操作系统文件系统缓存。
在任何类型的繁忙站点上使用 MyISAM 进行全文搜索都会让您感到悲伤。请改用 Sphinx 搜索。
While you can mix tables, I'd stick entirely with InnoDB. While MyISAM can be faster for some queries, InnoDB is usually quicker if properly tuned. If querying by primary key, InnoDB will pants MyISAM for speed, since InnoDB stores data in primary key order. MyISAM may be faster for secondary indexes.
MyISAM doesn't support transactions, and if you have 1000 tables, chances are you'll be updating several tables as part of one operation, and all those updates should be done inside a transaction (or be prepared for major headaches when concurrency becomes an issue when your game gets busy or your database lags!).
Sticking with one table type also makes memory management easier on the database machine. InnoDB gets dedicated RAM for caching, while MyISAM relies on the OS file-system cache.
Using MyISAM for fulltext search on any kind of busy site will cause you grief. Instead, use Sphinx Search.