简体   繁体   English

多个应用共享一个 MySQL 数据库

[英]Several apps sharing one MySQL database

I'm building project that has many apps in it (microservice architecture) and all of them are sharing one mysql database.我正在构建一个包含许多应用程序(微服务架构)的项目,并且它们都共享一个 mysql 数据库。 Is it possible to grant access to several tables in database?是否可以授予对数据库中多个表的访问权限? For example, I want that my app1 only has access to one table in database not all of them.例如,我希望我的 app1 只能访问数据库中的一个表,而不是所有表。 Thank you!谢谢!

Yes, you can grant various privileges to various users in MySQL, and in most database servers such as Postgres, H2, MS SQL Server, and so on.是的,您可以在 MySQL 和大多数数据库服务器(如 Postgres、H2、MS SQL 服务器等)中向各种用户授予各种权限

Create a user for each application.为每个应用程序创建一个用户。 Grant permissions to certain tables for each of those users.为每个用户授予对某些表的权限。

GRANT type_of_permission 
ON database_name.table_name 
TO ‘username’@'localhost’ 
;

Commonly used permissions include:常用的权限包括:

  • ALL PRIVILEGES (full access to database or entire database server) ALL PRIVILEGES(完全访问数据库或整个数据库服务器)
  • CREATE创造
  • DROP降低
  • DELETE删除
  • INSERT插入
  • SELECT SELECT
  • UPDATE更新
  • GRANT OPTION (granting/revoking privileges to other users) GRANT OPTION(授予/撤销其他用户的权限)

See tutorial at DigitalOcean.com .请参阅DigitalOcean.com 上的教程

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

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