为什么实际上需要多个数据库?
我正在查看 godaddy.com,它说他们提供最多 10 个 MySQL 数据库,但我不知道为什么你需要超过 1 个数据库,因为数据库可以有多个表。多个DB不能集成到一个DB中吗?是否有一个例子表明没有多个更好或不可行?当您想从他们的目录或名称中呼叫他们时,如何区分他们?
最好的,
I was looking at godaddy.com which says they offer up to 10 MySQL DBs, but I don't know why you would need more than 1 ever since a DB can have mutliple tables. Can't multiple DBs be integrated into a single DB? Is there an example case where its better or unfeasible to not have multiple ones? And how do you differentiate between them when you want to call them, from their directory or from a name?
Best,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想关注点分离将是最明显的答案。就像在面向对象编程中您可以将所有功能放在一个巨大的类中一样,将不相关的信息分开也是一个好主意。更容易理解较小的数据块,未来的开发人员可能会开始认为表是相关的,并以他们从未想过的方式聚合数据。
I guess separation of concerns would be the most obvious answer. In the same way you can have all of your functionality in one humongous class in object oriented programming, it's a good idea to keep non-related information separate. It's easier to wrap your head around smaller chunks of data, and future developers mights start to think tables are related, and aggregate data in a way they were never meant to.
想象一下,您正在与两个不同的团队一起执行两个不同的项目。也许您不会让一个团队访问其他团队的表。
每个数据库还可以有空间限制,并且每个数据库都可以配置特定的参数以优化性能。
另一方面,可以分配两个最终用户来备份每个整个数据库,并且您不希望一个用户备份另一个数据库,因为他可以在其他位置恢复数据库并访问第一个数据库数据库数据。
Imagine that you're doing two different projects with two different teams. Maybe you won't one team to access the other team tables.
There can also be a space limit in each database, and It each one can be configured with specific params to optimize the performance.
In other hand, two final users can be assigned to make the backups of each entire database, and you wan`t one user to make the backup of the other DB because he could be able to restore the database in other place and access the first database data.
我相信论坛上有一些非常好的DBA可以详细回答这个问题。
将表存储在不同的数据库中是因为您可以单独备份它们。此外,您将能够控制不同 NT 组(例如管理员与用户)对每个数据库的访问。尽管这可以在单个表级别完成,但有时授予或拒绝特定组对整个数据库的访问是有意义的。
当您需要在 SQL Server 中调用它们时,您需要将数据库名称附加到查询中,如
SELECT * FROM [MyDatabase].[dbo].[MyTable]
。I'm sure there are some pretty good DBAs on the forum who can answer this in detail.
Storing tables in different databases makes because you are able to backup them up individually. Furthermore, you will be able to control access to each database under different NT groups (e.g. Admin vs. users). Although this can be done at the indvidual table level, sometimes it makes sense to grant or deny access to an entire database to a particular group.
When you need to call them in SQL Server you need to append the database name to the query like this
SELECT * FROM [MyDatabase].[dbo].[MyTable]
.使用单独数据库的另一个原因与您是否需要完全事务恢复有关。例如,如果我有一堆表,这些表是通过导入过程按计划填充的,而不是由用户填充的,那么将它们放入单独的数据库中可以让我将恢复模式设置为简单,从而减少日志记录(当您一次加载数百万条记录)。我也不能像我对数据库中的数据以及用户插入的数据那样每十五分钟进行一次事务日志备份。它还可以在需要时使恢复过程更快,因为数据库会更小,因此单独恢复所需的时间更少。当整个服务器崩溃时,这并没有多大帮助,但如果只有一个数据库由于某种原因被损坏,它可能会有很大帮助。如果数据涉及不同的应用程序,则将数据存储在单独的数据库中也可以简化安全性。当然,有时我们有商业数据库,但我们无法向其中添加表格,因此可能需要一个单独的数据库来处理我们想要添加到数据中的一些内容(例如,我们使用项目管理软件来执行此操作,我们有一个Spearate 数据库,我们从 PM 系统中提取和汇总数据以进行报告,然后写下我们所有的客户报告。)
One other reason to use separate databases relates to whether you need full transactional recovery or not. For instance, if I havea bunch of tables that are populated on a schedule through import processes and never by the users, putting them in a separate database allows me to set the recovery mode to simple which reduces the logging (a good thing when you are loading millions of records at once). I can also not do transactional log backup every fifteen minutes like I do for the data in the database with the user inserted data. It could also make recovery a faster process when needed as the databases would be smaller and thus individally take less time to recover. Won't help much when the whole server crashes but it could help a lot if onely one datbase gets corrupted for some reason. If the data relates to different applications, it simplifies the security as well to have the data in separte databases. And of course sometimes we have commercial databases and we can;t add tables to those and so may need a separate database to handles some things we want to add to that data (we do this for instance with our Project Management software, we have a spearate database where we extract and summarize data from the PM system for reporting and then write all our custome reports off that.)