mysql——權限管理——授權、收回權限、查看授權


前期准備,新建一個用戶:

create user 'sww'@'localhost' identified by '123456';      /*創建一個用戶*/

select * from user;

mysql -h localhost -P 3306 -u sww -p123456       /*DOS窗口中登錄查看*/

 

 

 

 

 

========================================================================================

 

使用grant語句來創建新的用戶以及授權。在創建用戶時,可以為其用戶授權。但是必須擁有grant權限。

 

語法格式: 

 

                  grant   priv_type  [ colunm_list ] on  database.table

                  to   user   [ identified  by  [ PASSWORD ] 'password' ] 

                  [, user  [ identified  by  [ PASSWORD ] 'password' ]……

                  [ with with_option [ with_option ]…… ]

 

priv_type:表示權限類型;

colunm_list:表示權限作用於哪些列上,沒有該參數時,表示作用於整個表上;

database.table:表示新用戶的權限范圍,即只能在指定的數據庫和表上使用自己的權限;

user:表示新建用戶的賬戶,user由用戶名(user)和主機名(host)構成;

identified  by:關鍵字用來設置用戶的密碼;

password:表示用戶的密碼;如果密碼是一個普通的字符串,就不需要用PASSWORD關鍵字。

 

with后面帶有一個或者多個with_option參數,這個參數有5個選項:

 

grant option:被授權的用戶,可以將這些權限賦予給別的用戶;

max_queries_per_hour count:設置每小時允許執行的count次查詢;

max_updates_per_hour count:設置每小時允許執行的count次更新;

max_connections_per_hour count:設置每小時可以建立count連接;

max_user_connections count:設置單個用戶可以同時具有的count連接數;

 

---------------------------------------------------------------------------------------------------------------------------------

執行授權語句:

grant select,update on *.* to 'sww'@'localhost' identified by '123456' with grant option;

 

 

 

查詢授權信息:

show grants for 'sww'@'localhost';

 

 

 

 

或者:

select * from mysql.user;

 

 

 

 

 

 

收回部分權限:

revoke select on *.* from 'sww'@'localhost';   /*收回select權限*/

 

 

 

 

 

 

 

 

收回全部權限:

revoke all PRIVILEGES,GRANT option from 'sww'@'localhost';   /*收回全部權限*/

 

 

 

 

 

 

 

 

===========================================================

 

查看授權信息:

show grants for 'sww'@'localhost';

select * from mysql.user;

 

方法一:   select * from mysql.user;

 

方法二:   show grants for 'username'@'hostname';

 

username:表示用戶名;

 

hostname:表示主機名或者主機IP;

 

 

 

 

======================================================

 

收回權限:

revoke select on *.* from 'sww'@'localhost';   /*收回select權限*/

revoke all PRIVILEGES,GRANT option from 'sww'@'localhost';   /*收回全部權限*/

 

語法格式: 

 

                  revoke  priv_type  [ colunm_list ]……

                  on  database.table

                  from user [ ,user ]……

========================================================


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM