简体   繁体   English

多个数据库或具有大量内容的表

[英]Multiple Databases, or Tables with large content

I was going to post this on Database Administrators, but as it is slightly related to PHP, I felt it would be better to post here. 我本打算在数据库管理员上发布此文章,但由于它与PHP稍有关系,因此我觉得最好在此处发布。

I have a website that currently uses 8 databases, with tables within these databases that all link back to a particular table in the primary database (if that makes sense). 我有一个网站,当前使用8个数据库,这些数据库中的表都链接回主数据库中的特定表(如果有意义)。 I am aware that this is pretty poor design, everything I know is self-taught, so my knowledge with database design is pretty limited. 我知道这是非常糟糕的设计,我所知道的一切都是自学成才的,因此我对数据库设计的知识非常有限。 The reason for me originally designing the databases like this is because the content within them will be increasing exponentially. 我之所以这样设计数据库,是因为数据库中的内容将呈指数增长。 I therefore felt that I should spread the load into separate tables, but I couldn't do this without having separate databases (for complex reasons). 因此,我觉得我应该将负载分散到单独的表中,但是如果没有单独的数据库(出于复杂原因),我将无法做到这一点。

Currently, for each PHP script that I run, I initiate 8 connections to my MySQL Server, one for each database. 当前,对于我运行的每个PHP脚本,我都会启动与MySQL Server的8个连接,每个数据库一个。 I know this is bad!!! 我知道这很糟糕!!!

My colleague has suggested a complete redesign that uses just one database and a few tables, but with a lot more fields and a lot more content. 我的同事建议完全重新设计,该设计只使用一个数据库和几个表,但具有更多的字段和更多的内容。 My question is, quite simply, is he right? 我的问题很简单,他是对的吗? Should I try and combine all my databases into one and have as few tables as possible, even if the data is going to be pretty large? 即使数据很大,我是否应该尝试将所有数据库合并为一个数据库并尽可能少地使用表? The argument he puts forward, is that databases are designed to hold large amounts of data whether it be 10 million or 10 billion records. 他提出的论点是,数据库旨在容纳大量数据,无论是1000万还是100亿条记录。 This is their job, so I should just trust them and design the database in a way that works easiest for me. 这是他们的工作,所以我应该信任他们,并以对我来说最简单的方式设计数据库。

I have read through the following Stackoverflow questions but I think my question is slightly different for the reason that the database is likely to have an extremely large amount of content and therefore the answer may be different. 我已经阅读了以下Stackoverflow问题,但是我认为我的问题略有不同,原因是数据库可能包含大量内容,因此答案可能有所不同。 Apologies if not! 不好意思!

  1. Large websites - multiple databases or or multiple tables? 大型网站-多个数据库还是多个表?
  2. Multiple databases tables or combined into one 多个数据库表或合并为一个

Thanks in advance 提前致谢

My question is, quite simply, is he right? 我的问题很简单,他是对的吗?

Yes, you need to keep your database hits as low as possible, not to increase it. 是的,您需要保持数据库命中率尽可能低,而不是增加它。 If you have only one user, you open 8 connections. 如果只有一个用户,则打开8个连接。 If you have two, you suddenly need 16! 如果您有两个,则突然需要16个! Three - 24!! 三-24! How you came to conclusion, that this would spread the load? 您如何得出结论,这将分散负载? In my opinion it actually does the opposite, not mentioning problems with relational data and the design of the application itself. 在我看来,它实际上是相反的,没有提到关系数据和应用程序本身的设计问题。

So, some basic rules: 因此,一些基本规则:

database - one application -> one database (unless really necessary and you need to know WHY and HOW to do that) 数据库 -一个应用程序->一个数据库(除非真的必要,并且您需要知道为什么和怎么做)

tables , columns - depends on the data you need to store, but generally you want to make it simple, flexible and easy to maintain over time, especially if it is a huge website (or plan to be). 表格 -取决于您需要存储的数据,但是通常您希望使其随时间推移变得简单,灵活且易于维护,尤其是在它是一个庞大的网站(或计划成为网站)时。

If you'd have a query, that needs to select the data from multiple tables, you wouldn't write multiple queries either, right? 如果您有一个查询,需要从多个表中选择数据,那么您也不会编写多个查询,对吗? You'd write one query with "joins" to do only one database hit, and it's basically the same principle with having multiple databases... 您只需使用“ joins”编写一个查询就可以完成一个数据库命中,并且拥有多个数据库基本上是相同的原理...

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

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