mysql 用户权限管理常用命令

by pxz


发布于: 2014-12-12 所属分类: 数据库 mysql 标签: 权限  105


<h3 id="h3-1-mysql-"><a name="1. 查看MySQL用户权限" class="reference-link"></a><span class="header-link octicon octicon-link"></span>1. 查看MySQL用户权限</h3><pre><code>show grants for root@'localhost'; </code></pre><h3 id="h3-2-mysql-"><a name="2. 新建MySQL用户" class="reference-link"></a><span class="header-link octicon octicon-link"></span>2. 新建MySQL用户</h3><p>a. 给来自localhost的用户test分配可对所有数据库所有表进行select,insert,update,delete,create,drop,index,alter操作的权限,并设定口令为123 </p> <pre><code>grant select,insert,update,delete,create,drop,index,alter on *.* to test@localhost identified by '123'; </code></pre><p>b. 给来自localhost的用户test分配可对所有数据库所有表进行所有操作的权限</p> <pre><code>grant all privileges on *.* to test@localhost; </code></pre><h3 id="h3-3-mysql-"><a name="3. 编辑修改MySQL用户权限" class="reference-link"></a><span class="header-link octicon octicon-link"></span>3. 编辑修改MySQL用户权限</h3><p>a. 取消一个账户和其权限</p> <pre><code>Drop USER username; Drop USER username@'%'; Drop USER username@localhost; </code></pre><p>b. 取消授权用户:</p> <p>语法:<code>REVOKE privilege ON databasename.tablename FROM 'username'@'host';</code><br>例子:</p> <pre><code>REVOKE SELECT ON *.* FROM 'pig'@'%'; REVOKE SELECT ON test.user FROM 'pig'@'%'; REVOKE all on *.* from pig@localhost; REVOKE all on user.* from 'admin'@'%'; </code></pre><p>c. 删除用户:</p> <p>语法: <code>delete from user where user = "user_name" and host = "host_name" ;</code><br>例子:</p> <pre><code>delete from user where user='test' and host='localhost'; //同 drop user test@localhost; </code></pre><h3 id="h3-4-"><a name="4. 使设置生效" class="reference-link"></a><span class="header-link octicon octicon-link"></span>4. 使设置生效</h3><pre><code>FLUSH PRIVILEGES </code></pre>

发表评论

暂无评论

搜索
用户登陆