当前位置:Gxlcms > mysql > SQL2012用户只能看到自己拥有权限的库

SQL2012用户只能看到自己拥有权限的库

时间:2021-07-01 10:21:17 帮助过:34人阅读

SQL 2012用户只能看到自己拥有权限的库 呢,下面给大家参考参考。

以SQL Server 2012 为例

110336_8w02_99943[2]

上图是部分数据库的截图, 我们执行

  1. <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
  2. <tbody><tr>
  3. <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
  4. <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7675')"></td>
  5. </tr>
  6. <tr>
  7. <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy7675"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>DENY VIEW any DATABASE to PUBLIC;</li></ol></pre>
  8. </td>
  9. </tr>
  10. </tbody></table>然后给Best库的Best用户执行

  1. <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
  2. <tbody><tr>
  3. <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
  4. <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy5818')"></td>
  5. </tr>
  6. <tr>
  7. <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy5818"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>ALTER AUTHORIZATION ON DATABASE::Best TO Best</li></ol></pre>
  8. </td>
  9. </tr>
  10. </tbody></table><img title="H80O8P922`NXMA2FRC~60AH" alt="H80O8P922`NXMA2FRC~60AH" width="350" height="181" src="https://www.gxlcms.com/help/uploads/allimg/c130422/13B600b92G0-251F.jpg">

资源管理器中Best用户登陆后就只能显示Best库了, 同样给Mine库的Mine用户执行相同SQL

  1. <table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
  2. <tbody><tr>
  3. <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
  4. <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy8201')"></td>
  5. </tr>
  6. <tr>
  7. <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id="copy8201"><pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li>ALTER AUTHORIZATION ON DATABASE::Mine TO Mine</li></ol></pre>
  8. </td>
  9. </tr>
  10. </tbody></table><img title="KM030PFB~D8GJO7R3CV%8YG" alt="KM030PFB~D8GJO7R3CV%8YG" width="353" height="163" src="https://www.gxlcms.com/help/uploads/allimg/c130422/13B600bb3620-35164.jpg">

Mine用户登录后也只能显示Mine数据库了, 达到了咱的目的, 分配权限的时候记得给对应用户映射对应数据库的权限, 防止跨库操作.

人气教程排行