简体   繁体   English

如何处理用户对可以访问多个数据库的应用程序的访问

[英]How to handle user access to an application that can access multiple databases

I am considering a way of taking an existing php and mysql application that was developed for use in-house (and thus has a single database with nothing built in in terms of multi-tenancy). 我正在考虑采用一种已开发供内部使用的现有php和mysql应用程序的方法(因此,该数据库具有一个单一的数据库,在多租户方面没有任何内置)。

I figured that it's possible and maybe in some way better to run each client of their own database. 我认为可以运行自己的数据库的每个客户端,并且可能以某种方式更好。 What I want to know is how best to handle the login of a user given the credentials supplied could be in any one of the databases and in some cases possibly multiple databases. 我想知道的是,鉴于所提供的凭据可能位于任何一个数据库中,并且在某些情况下可能是多个数据库中,如何最好地处理用户的登录。

I had thought along the lines of iterating through each database and checking for valid credentials. 我曾经考虑过遍历每个数据库并检查有效的凭证。 If the credentials exist in multiples then return a list that the user chooses from, or if it exists only once then just logging in. 如果凭据以倍数形式存在,则返回用户选择的列表,或者如果仅存在一次,则仅登录。

Is that a valid solution? 那是一个有效的解决方案吗? Will it start to perform badly IF the application was to expand to have thousands of users across hundreds of databases? 如果应用程序要扩展到数百个数据库中的数千个用户,它将开始表现不佳吗?

I recommend installing a different instance of the app for each client, with their own database. 我建议为每个客户端安装一个具有自己数据库的应用程序的不同实例。

Each client should be given their own url to access the app, instead of having them all access in from 1 location, but pointing to multiple databases. 应该为每个客户端提供自己的URL来访问该应用程序,而不是让它们都从1个位置进行访问,而是指向多个数据库。

This will adress a few problems that you might encounter if you run all your clients from 1 location (multiple databases) 如果您从1个位置运行所有客户端(多个数据库),这将解决您可能遇到的一些问题。

  1. What happend if the different client has accounts with the same name? 如果另一个客户拥有相同名称的帐户,会发生什么情况? Which account will take precedence? 哪个帐户优先?
  2. What happens if the client want to take over the app and host it seperately from the rest of the clients. 如果客户端要接管该应用程序并将其与其他客户端分开托管,会发生什么情况。 How can you easily seperate out this client into a sepetare installation? 您如何轻松地将此客户端分离为sepetare安装?

Another point to note, connecting and disconnecting to databases are expensive. 还有一点要注意,连接和断开数据库很昂贵。 If you have to do so 100 times when the user logs in to find out which database that user is in. It might bogg down the system or your database server. 如果用户登录时必须这样做100次才能找出该用户所在的数据库。这可能会使系统或数据库服务器瘫痪。

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

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