简体   繁体   English

共享的多租户MySQL数据库中的可伸缩性

[英]Scalability in shared multi-tenant MySQL database

I am designing common web-based CRM application for huge number of tenants. 我正在为大量租户设计基于Web的通用CRM应用程序。 Users (tenants) sign up online for use of the application. 用户(租户)在线注册以使用该应用程序。 Initially, there will not be so many users but in future there are possibilities. 最初,不会有那么多用户,但是将来会有可能。

I want to use single shared MySQL database. 我想使用单个共享的MySQL数据库。 It will be impossible to create separate database for each tenant because of the chosen scenario and future functionality integrations. 由于选择的方案和将来的功能集成,将不可能为每个租户创建单独的数据库。 The programming will be in PHP. 编程将使用PHP。

But, how should I address data scalability issues: 但是,我应该如何解决数据可伸缩性问题:

  1. What if rows in the table exceed the size of table. 如果表中的行超过表的大小怎么办? How to address this issue? 如何解决这个问题?
  2. If I use auto increment BIGINT primary key, for example for 'contacts' table. 如果我使用自动递增BIGINT主键,例如用于“联系人”表。 What will happen after the largest value of BIGINT reached? 在达到BIGINT的最大值之后会发生什么?
  3. Is it best practice to use foreign key constraints in real huge data tables? 在真正的大型数据表中使用外键约束是否是最佳实践? How will it affect the performance of the application, if used or not used? 如果使用或不使用,它将如何影响应用程序的性能?
  4. Will MySQL be good fit for this kind of applications? MySQL是否适合此类应用程序?
  5. What is Zoho CRM's database technique for multi-tenancy? Zoho CRM的多租户数据库技术是什么?

MySQL is pretty good a scaling up , even with enormous tables. MySQL是相当不错的比例 ,即使有巨大的表。 Basically you can just put your database on larger and more powerful servers to handle the demand. 基本上,您可以将数据库放在更大,功能更强大的服务器上,以处理需求。 In my experience it's usually limited by RAM. 以我的经验,它通常受RAM限制。

Once that technique starts getting dicey you can scale out by creating read replicas of the database. 一旦该技术开始变得冒险,你可以通过创建数据库的读副本向外扩展。 Basically these are read-only copies of your master database that are continuously synchronized with the master. 基本上,这些是主数据库的只读副本,这些副本与主数据库连续同步。 In your application use two different database connections. 在您的应用程序中,使用两个不同的数据库连接。 The first connection is to a read-replica and is used for all SELECT statements. 第一个连接到一个只读副本,并用于所有SELECT语句。 The other connection is to your master to be used for all INSERT, UPDATE, and DELETE statements. 另一个连接是您的主数据库,该数据库将用于所有INSERT,UPDATE和DELETE语句。 Since many applications do more SELECTs than anything else and there is very little limit on how many read-replicas you can create this will greatly expand your potential scale. 由于许多应用程序执行的SELECT比其他任何操作都要多,并且可以创建的只读副本数量几乎没有限制,这将极大地扩展您的潜在规模。

In MySQL I tend to use a single database for all tenants and segment the data by using different database usernames for each tenant. 在MySQL中,我倾向于为所有租户使用一个数据库,并通过为每个租户使用不同的数据库用户名来分割数据。 Through a tenant_id column and views that filter by the tenant_id I can assure that tenants don't have any access to other tenant's data. 通过tenant_id列和按tenant_id筛选的视图,我可以确保租户无法访问其他租户的数据。 I wrote a blog post on how I was able to convert a single-tenant application to multi-tenant in a weekend: https://opensource.io/it/mysql-multi-tenant/ 我写了一篇博客文章,介绍如何在周末将单租户应用程序转换为多租户: https : //opensource.io/it/mysql-multi-tenant/

Having a single database and single codebase for all tenants is much easier to maintain than multiple databases or schemas. 对于所有租户来说,拥有一个数据库和一个代码库比维护多个数据库或模式要容易得多。

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

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