最佳实践是什么?对每个用户使用不同的数据库,或者使用userid coloumn相同的数据库

时间:2021-06-04 20:05:41

What is the best practice? use different database for every users or use same database with userid coloumn.

最佳实践是什么?对每个用户使用不同的数据库,或者使用userid coloumn相同的数据库。

I am working on mysql database and php. I having a little bit confusion about my project.

我正在使用mysql数据库和php。我对我的项目有点困惑。

My project is user based. If a user has been registered then he can store data on a many tables. I have created all tables with userid column to find data for particular user. But now I am thinking about it if tables having huge amount of rows then my project will getting slow to fetch records.

我的项目是基于用户的。如果用户已经注册,那么他可以在多个表上存储数据。我用userid列创建了所有表,以查找特定用户的数据。但是现在我在考虑如果表有大量的行,那么我的项目获取记录就会变慢。

Now the confusion is "what is the best practice use different database for every users or use same database with userid coloumn."

现在的困惑是“什么是最佳实践,对每个用户使用不同的数据库,或者使用userid coloumn相同的数据库。”

2 个解决方案

#1


2  

Use one database.

使用一个数据库。

Using different database will not help scalability if you have a "huge amount of rows". Acquiring a database connection is much slower in general than simple queries, especially those running against indexed columns like primary keys and unique keys. (A popular webhost considers the performance equivalence of connections to queries as 25:1)

如果您有“大量的行”,那么使用不同的数据库将不利于可伸缩性。获取数据库连接通常要比简单查询慢得多,特别是那些针对主键和惟一键等索引列运行的查询。(一个流行的webhost将查询连接的性能等价性视为25:1)

If you are worried about scalability, you'll need to read up on database connection pools, database indexes, and, in extremely large datasets, database sharding.

如果您担心可伸缩性,那么需要阅读数据库连接池、数据库索引,以及超大数据集中的数据库分片。

I've never heard of using different databases per user. I've heard of hosted applications that host data for third-party customers use different databases for each customer in order to keep data completely separate (the alternative, hosting all customers' data in one database, is called multitenancy).

我从未听说过每个用户使用不同的数据库。我听说过托管的应用程序,为每个客户使用不同的数据库为每个客户使用不同的数据库,以保持数据完全独立(另一种方法,在一个数据库中托管所有客户的数据,称为多租户)。

#2


0  

Use one database only,

只使用一个数据库,

For scaling it further you can use many things like:-

为了进一步扩展它,你可以使用很多东西,比如:-

  1. sharding of user table. MySQL sharding approaches?
  2. 用户表的切分。MySQL分片的方法吗?
  3. Mysql Partitioning (http://dev.mysql.com/doc/refman/5.1/en/partitioning.html)
  4. Mysql分区(http://dev.mysql.com/doc/refman/5.1/en/partitioning.html)
  5. using Master- slave configurations (insert/update/delete on master and select on slave)
  6. 使用主-从配置(在主服务器上插入/更新/删除,在从服务器上选择)
  7. a caching layer over mysql like (Redis/Memcache)
  8. 类似于mysql的缓存层(Redis/Memcache)
  9. optimizing table structures, using primary key in where clause
  10. 使用where子句中的主键优化表结构
  11. putting right indexing on table structure.
  12. 在表结构上设置正确的索引。

#1


2  

Use one database.

使用一个数据库。

Using different database will not help scalability if you have a "huge amount of rows". Acquiring a database connection is much slower in general than simple queries, especially those running against indexed columns like primary keys and unique keys. (A popular webhost considers the performance equivalence of connections to queries as 25:1)

如果您有“大量的行”,那么使用不同的数据库将不利于可伸缩性。获取数据库连接通常要比简单查询慢得多,特别是那些针对主键和惟一键等索引列运行的查询。(一个流行的webhost将查询连接的性能等价性视为25:1)

If you are worried about scalability, you'll need to read up on database connection pools, database indexes, and, in extremely large datasets, database sharding.

如果您担心可伸缩性,那么需要阅读数据库连接池、数据库索引,以及超大数据集中的数据库分片。

I've never heard of using different databases per user. I've heard of hosted applications that host data for third-party customers use different databases for each customer in order to keep data completely separate (the alternative, hosting all customers' data in one database, is called multitenancy).

我从未听说过每个用户使用不同的数据库。我听说过托管的应用程序,为每个客户使用不同的数据库为每个客户使用不同的数据库,以保持数据完全独立(另一种方法,在一个数据库中托管所有客户的数据,称为多租户)。

#2


0  

Use one database only,

只使用一个数据库,

For scaling it further you can use many things like:-

为了进一步扩展它,你可以使用很多东西,比如:-

  1. sharding of user table. MySQL sharding approaches?
  2. 用户表的切分。MySQL分片的方法吗?
  3. Mysql Partitioning (http://dev.mysql.com/doc/refman/5.1/en/partitioning.html)
  4. Mysql分区(http://dev.mysql.com/doc/refman/5.1/en/partitioning.html)
  5. using Master- slave configurations (insert/update/delete on master and select on slave)
  6. 使用主-从配置(在主服务器上插入/更新/删除,在从服务器上选择)
  7. a caching layer over mysql like (Redis/Memcache)
  8. 类似于mysql的缓存层(Redis/Memcache)
  9. optimizing table structures, using primary key in where clause
  10. 使用where子句中的主键优化表结构
  11. putting right indexing on table structure.
  12. 在表结构上设置正确的索引。