AWS RDS - Microsoft SQL Server Express - 无法添加具有查看/创建数据库权限的用户

时间:2017-11-04 15:47:05

标签: sql-server amazon-web-services permissions relational-database amazon-rds

我在Amazon Web Services帐户上创建了一个SQL Server Express。在此过程中,我必须创建一个主用户名/密码。有了这些凭据,我就能够在服务器上创建和查看任何数据库,以及其他登录信息。

我创建了一个单独的登录,但根据AWS文档,它不会让我分配以下任何角色:

  

http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_SQLServer.html   以下服务器级角色在Amazon RDS中当前可用

bulkadmin
dbcreator
diskadmin
securityadmin
serveradmin
sysadmin

如何在此数据库上创建单独的用户帐户,并具有对数据库的完全访问权限?到目前为止,创建的任何新用户都无法创建数据库或查看任何现有数据。

1 个答案:

答案 0 :(得分:2)

以下是一系列命令,您可以在Microsoft SQL Server Management Studio中运行这些命令,以创建具有所需权限的用户。

将NewUserName替换为新用户的名称。用新密码替换myPassword。

USE master;
 GO

CREATE LOGIN [NewUserName]
 WITH PASSWORD = N'myPassword',
 CHECK_POLICY = OFF,
 CHECK_EXPIRATION = OFF;
 GO

GRANT ALTER ANY CONNECTION TO [NewUserName] WITH GRANT OPTION;
 GRANT ALTER ANY LINKED SERVER TO [NewUserName] WITH GRANT OPTION;
 GRANT ALTER ANY LOGIN TO [NewUserName] WITH GRANT OPTION;
 GRANT ALTER SERVER STATE TO [NewUserName] WITH GRANT OPTION;
 GRANT ALTER TRACE TO [NewUserName] WITH GRANT OPTION;
 GRANT CREATE ANY DATABASE TO [NewUserName] WITH GRANT OPTION;
 GRANT VIEW ANY DATABASE TO [NewUserName] WITH GRANT OPTION;
 GRANT VIEW ANY DEFINITION TO [NewUserName] WITH GRANT OPTION;
 GRANT VIEW SERVER STATE TO [NewUserName] WITH GRANT OPTION;

EXEC sp_MSforeachdb '
 DECLARE @name VARCHAR(500)
 SET @name=''?''
 IF DB_ID(@name) > 5
 BEGIN
 USE [?]
 CREATE USER NewUserName FOR LOGIN NewUserName;
 EXEC sp_addrolemember ''db_owner'',''NewUserName''
 END'