简体   繁体   English

单个数据库或多个数据库(一次使用多个用户)

[英]Single DB or multiple DB (for multiple users in a single aplication)

I´m new on php/mysql, and i´m codding a simple CMS. 我是php / mysql的新手,并且编写了一个简单的CMS。 But in this case i will host multiple companies (each company with their multiple users), that pays a fee to use the system. 但是在这种情况下,我将托管多个公司(每个公司及其多个用户),这需要付费才能使用该系统。

So... My question is about how to organize the Data Base... Talking about security, management and performance, i just want to know the opinion of ou guys of wich of these cases is the best: 所以...我的问题是关于如何组织数据库...关于安全性,管理和性能,我只想知道这些情况中最重要的一个的看法:

  1. Host all companies on a single DB and they get a company id to match with the users. 将所有公司托管在一个数据库中,它们会获得一个公司ID以与用户匹配。

  2. Each company have a separated DB that holds the users in there (and dont need the companies id anymore). 每个公司都有一个单独的数据库,用于将用户保留在其中(并且不再需要公司ID)。

I would start the development following the first situation... But than i thought if i have some hacker attack / sql injection, every client would be harmed. 我将在出现第一种情况后开始开发...但是比我想想,如果我有一些黑客攻击/ SQL注入,每个客户端都会受到伤害。 Having separated DBs, the damage will get only one client. 分离数据库后,损坏只会得到一个客户。 So maybe the 2nd situation could be better in terms of security. 因此,就安全性而言,第二种情况可能会更好。 But could not say the same about management and performance. 但是对于管理和性能却不能说相同的话。

So, based on your experience, any help or tip would be great! 因此,根据您的经验,任何帮助或小费都将非常有用!

Thanks in advance, and sorry about my poor english. 在此先感谢您,我的英语不好对不起。

I would go for seperate DBs. 我会去单独的数据库。 But not only for hacking. 但不仅是黑客。

Scalability: Lets say you have a server that handles 10 websites, but 1 of those websites in growing fast in requests, content, etc. Your server is having a hard time to host all of them. 可伸缩性:假设您有一台服务器可以处理10个网站,但是其中一个网站的请求,内容等正在快速增长。您的服务器很难托管所有这些网站。

With seperate DB's it is a piece of cake to spread over multiple servers. 使用独立的DB,可以轻松地分布在多个服务器上。 With a single one you would have to upgrade you current DB or cluster it, but that is sometimes not possible with the hosting company or very expensive. 如果只有一个数据库,则必须升级当前的数据库或对其进行群集,但这有时对于托管公司而言是不可能的,或者成本很高。

Performance: You they are all on 1 DB and data of multiple users is in 1 table, locks might slow down other users. 性能:您全部位于1个DB上,多个用户的数据位于1个表中,锁可能会使其他用户的速度变慢。

Large tables, mean large indices, large lookups, etc. So splitting to diffrent DB's would actualy speed that up. 大表,大索引,大查询等。因此,拆分为不同的DB可以实际上加快速度。

You would have to deal with extra memory and CPU overhead per DB but they normaly do not have an amazingly large impact. 您必须处理每个DB的额外内存和CPU开销,但是它们通常不会产生令人惊讶的巨大影响。

And yes, management for multiple DBs is more work, but having proper update scripts and keeping a good eye on the versions of the DB schema will reduce your management concerns a lot. 是的,管理多个数据库需要做更多的工作,但是拥有适当的更新脚本并密切注意数据库架构的版本将大大减少管理方面的麻烦。

Update: also see this article. 更新:另请参阅本文。 http://msdn.microsoft.com/en-us/library/aa479086.aspx http://msdn.microsoft.com/en-us/library/aa479086.aspx

分离的DB具有许多优势,包括性能,安全性,可伸缩性,移动性等。尝试将所有内容打包到1个数据库中的风险更少,而报酬则更少,尤其是在谈论分离的公司数据时。

You haven't provided any details, but generally speaking, I would opt for separate databases. 您没有提供任何详细信息,但是一般而言,我会选择单独的数据库。

Using an autonomous database for every client allows a finer degree of control, as it would be possible to manage/backup/trash/etc. 对每个客户端使用自治数据库可以实现更好的控制,因为可以进行管理/备份/废纸/等。 them individually, without affecting the others. 他们单独,而不影响其他人。 It would also require less grooming, as data is easier to be distinguished, and one database cannot break the others. 它还将需要较少的修饰,因为更易于区分数据,并且一个数据库无法破坏其他数据库。

Not to mention it would make the development process easier -- note that separate databases mean that you don't have to always verify the "owner" of the rows. 更不用说这会使开发过程更容易-请注意,单独的数据库意味着您不必始终验证行的“所有者”。

If you plan to have this database hosted in a cloud environment such as Azure databases where resources are (relatively) cheap, clients are running the same code base, the database schema is the same (obviously), and there is the possibility of sharing some data between the companies then a multi-tenant database may be the way to go. 如果您打算将此数据库托管在(相对)便宜的云环境(例如Azure数据库)中,客户端运行的是相同的代码库,数据库架构是相同的(显然),并且有可能共享某些数据库公司之间的数据,然后多租户数据库可能是要走的路。 For anything else you, you will probably be creating a lot of extra work going with a multi-tenant database. 对于其他任何事情,您可能会在多租户数据库上创建很多额外的工作。

Keep in mind that if you go the separate databases route, trying to migrate to a multi-tenant cloud solution later on is a HUGE task. 请记住,如果您走单独的数据库路线,稍后再尝试迁移到多租户云解决方案是一项巨大的任务。 I only mention this because all I've been hearing for the past few years around the IT water coolers is "Cloud! Cloud! Cloud!". 我之所以仅提及这一点,是因为过去几年来我一直在听到有关IT饮水机的信息是“ Cloud!Cloud!Cloud!”。

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

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