数据库安全性操作

版权声明:欢迎转载,若转载,请标明出处,若发现错误,欢迎指出 https://blog.csdn.net/lz161530245/article/details/84317176

哈哈哈!作业来啦!交任务啦!终于找到啦!看到的宝宝们开心吗?哈哈哈哈O(∩_∩)O哈哈~

以下内容仅供参考哈,有错误的地方欢迎交流,博主也正在学习中ing

1. 创建登录名并配置角色及用户

(1)使用sa登录SQLServer2008;

       手动启动SQLServer2008,以sa成功登陆

 

(2)创建数据库sa_test,其中创建数据表dbo.saTable;

             create database sa_test;

use sa_test;

create table dbo.saTable(

 id int primary key,

 name varchar(10)

 )

成功创建数据库sa_test,并成功创建数据表dbo.saTable

 

(3)创建登录名L1,具有dbcreator权限,影射用户名U1,默认数据库sa_test,数据库角色为public;

数据库——>安全性——>登录名——>新建登录名——>登录名为L1,选SQL Server身份验证,设置密码,默认数据库选择sa_test,数据库角色默认为public,另外选择具有dbcreator权限。

sa_test——>安全性——>用户——>新建用户——>用户名为U1,选择映射的登录名为L1

 

(4)创建登录名L2,具有dbcreator权限,影射用户名U2,默认数据库sa_test,数据库角色为public。

数据库——>安全性——>登录名——>新建登录名——>登录名为L2,选SQL Server身份验证,设置密码,默认数据库选择sa_test,数据库角色默认为public,另外选择具有dbcreator权限。

sa_test——>安全性——>用户——>新建用户——>用户名为U2,选择映射的登录名为L2

 

2. 使用新登录名登录服务器并验证权限

(1)使用L1登录SQLServer2008,验证是否可以浏览表dbo.saTable;

       以L1登陆SQLServer2008,不可以浏览表dbo.saTable

 

(2)创建数据库L1_test,用户名默认为dbo,模式默认为dbo;

       create database L1_test;

成功创建数据库L1_test,用户名默认为dbo,模式默认为dbo

 

(3)在L1_test中创建数据表dbo.L1Table;

              use L1_test;

create table L1Table(   

 id int primary key,

 name varchar(10)

)

成功在L1_test中创建数据表dbo.L1Table

 

(4)使用L2登录SQLServer2008,验证是否可以浏览表dbo.saTable;

       以L2登陆SQLServer2008,不可以浏览表dbo.saTable

 

(5)创建数据库L2_test,用户名默认为dbo,模式默认为dbo;

       create database L2_test;

成功创建数据库L2_test,用户名默认为dbo,模式默认为dbo

 

(6)在L2_test中创建数据表dbo.L2Table。

       use L2_test;

              create table L2Table(   

           id int primary key,

 name varchar(10)

    )

成功在L2_test中创建数据表dbo.L2Table

 

3. sa用户对新建用户授权

(1)使用sa登录SQLServer2008;

       以使用sa正确成功登陆SQLServer2008

 

(2)设置U1用户在L2_test中具备public权限;

登录L2——>L2_test——>安全性——>用户——>新建用户——>设置用户名为U1,登录名为L1

 

(3)设置U2用户在L1_test中具备public权限;

登录L1——>L1_test——>安全性——>用户——>新建用户——>设置用户名为U2,登录名为L1

 

(4)授权U1在dbo.saTable上的select权限;

              use sa_test;

grant select

on dbo.saTable

to U1

with grant option

成功授权U1在dbo.saTable上的select权限

 

(5)授权U2在dbo.saTable上的insert权限。

       use sa_test;

grant insert

on dbo.saTable

to U2

with grant option

成功授权U2在dbo.saTable上的insert权限

 

4. 新建用户之间授权

(1)使用L1登录SQLServer2008,验证是否可以浏览表dbo.saTable中的数据,是否可以插入数据;

              use sa_test;

select *

from saTable

使用L1登录SQLServer2008,不可以浏览表dbo.saTable中的数据。

insert into saTable values(1,'张丽');

不可以插入数据。

 

(2)授权U2在dbo.L1Table上的select权限和insert权限;

grant select,insert

to U2

成功授权U2在dbo.L1Table上的select权限和insert权限

 

(3)授权U2在L1_test中创建表的权限;

grant create table

to U2

成功授权U2在L1_test中创建表的权限

 

(4)授权U2在L1_test中创建模式的权限。

grant create schema

to U2

成功授权U2在L1_test中创建模式的权限

 

5. 验证用户权限并对指定属性授权

(1)使用L2登录SQLServer2008,验证是否可以浏览表dbo.saTable中的数据,是否可以插入数据;

use sa_test;

select *

from saTable

使用L2登录SQLServer2008,可以浏览表dbo.saTable中的数据。

insert into saTable

values(3,'哈哈')

使用L2登录SQLServer2008,可以插入往dbo.saTable中插入数据。

 

(2)验证是否可以浏览表dbo.L1Table中数据,是否可以插入数据;

use L1_test

select *

from L1Table

可以浏览表dbo.L1Table中数据

insert into L1Table

values(1,'哈哈')

可以插入数据

 

(3)创建U2用户的数据库模式UU,验证是否成功;

create schema "UU" authorization U2

在L1中L_test数据库下操作该语句成功

 

(4)创建数据表UU.Test,验证是否成功(语句创建成功);

create table UU.Test(

id int primary key,

tt char(10)

)

在L1中L_test数据库下操作该语句成功

 

(5)验证U2是否具备UU.Test的全部权限,如drop;

              use L1_test

select *

from UU.Test;

       查询成功

 

use L1_test

drop table UU.Test

       删除成功

 

use L1_test

insert into UU.Test

values(1,'恩恩');

插入成功

 

(6)授权U1在dbo.L2Table上的select权限和修改指定列的权限。

use L2_Test

grant select,update(name)

on L2Table

to U1

成功授权U1在dbo.L2Table上的select权限和修改指定列的权限

 

6. 收回权限并验证

(1)使用L1登录SQLServer2008,验证是否可以浏览dbo.L2Table中数据,是否可以修改指定的列;

use L2_test

select *

from L2Table

 

use L2_test

update L2Table

set name='无二'

where id=1

使用L1登录SQLServer2008,可以浏览dbo.L2Table中数据,可以修改指定的列

 

(2)收回U2在dbo.L1Table上的insert权限;

use L1_test

revoke insert

on L1Table

from U2

成功收回U2在dbo.L1Table上的insert权限

 

(3)使用L2登录SQLServer2008,验证是否可以浏览表uu1.L1Table中数据,是否可以插入数据。

use L2_test

select *

from UU.L1Table

 

use L2_test

insert into L1Table

valus(3,'积极')

使用L2登录SQLServer2008,不可以浏览表uu1.L1Table中数据,不可以插入数据

 

7. 创建角色并授权

(1)使用L1登录SQLServer2008,在L1_test中创建数据表dbo.L1Table2;

              成功使用L1登录SQLServer2008

use L1_test

create table L1Table2(  

       id int primary key,

       name varchar(10)

    )

成功在L1_test中创建数据表dbo.L1Table2

 

(2)创建数据库角色R1;

create role R1

成功创建数据库角色R1

 

(3)将在dbo.L1Table表上的查询和插入权限授予角色R1,将dbo.L1Table2表上的查询权限和修改指定列权限授予角色R1;

grant select,insert

on dbo.L1Table

to R1

 

grant select,update(name)

on dbo.L1Table2

to R1

成功将在dbo.L1Table表上的查询和插入权限授予角色R1,并成功将dbo.L1Table2表上的查询权限和修改指定列权限授予角色R1

 

(4)将用户添加到角色R1中;

exec sp_addrolemember R1,U2

用户成功添加到角色R1中

 

(5)使用L2登录SQLServer2008,验证对L1_test中数据表的操作权限。

use L1_test

select *

from L1Table

可以查询

 

use L1_test

insert into L1Table

values(2,'哟哟')

可以插入

 

use L1_test

update L1Table

set name='破破'

where id=1

不可以更新

 

use L1_Test

delete from L1Table

where id=1

不可以删除

 

8. 收回角色的权限

(1)使用L1登录SQLServer2008,收回角色R1在dbo.L1Table表上的插入权限;

revoke insert

on L1Table

from R1

成功使用L1登录SQLServer2008,成功收回角色R1在dbo.L1Table表上的插入权限

 

(2)使用L2登录SQLServer2008,验证对L1_test中数据表的操作权限。

use L1_test

select *

from L1Table

可以查询

 

use L1_test

insert into L1Table

values(3,'谷歌')

不可以插入

 

use L1_test

update L1Table

set name='可怕'

where id=1

不可以更新

 

use L1_test

delete from L1Table

where id=1

不可以删除

猜你喜欢

转载自blog.csdn.net/lz161530245/article/details/84317176