萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> mysql grant查看用戶權限命令

mysql grant查看用戶權限命令

本文章來給大家總結一些常用的來查看mysql用戶權限命令的一些方法總結,在mysql中查看用戶權限命令是show grants for了,下面我來詳細介紹grants這個命令,有需要了解的朋友可參考。

語句

 代碼如下 復制代碼

show grants for 你的用戶

比如:

 代碼如下 復制代碼

show grants for root@'localhost';

查看用戶權限。

 代碼如下 復制代碼

show grants for 你的用戶;
show grants for root@'localhost';
show grants for [email protected];
show create database dbname;  這個可以看到創建數據庫時用到的一些參數。
show create table tickets;    可以看到創建表時用到的一些參數


查看MYSQL數據庫中所有用戶

 

 代碼如下 復制代碼 mysql>SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
+---------------------------------------+
| query                                 |
+---------------------------------------+
| User:;                |
| User: ;              |
| User: ;                      |
| User: ;                     |
| User: ;                    |
| User: ;                   |
| User: ;             |
| User: ;           |
| User: ;       |
| User: ;  |
| User: ;       |
| User: ;                 |
| User: ;            |
| User: ;        |
| User: ;              |
| User: ;          |
| User: ;         |
| User: ;             |
| User: ;           |
| User: ;     |
| User: ; |
+---------------------------------------+
21 rows in set (0.01 sec)

 
 
查看數據庫中具體某個用戶的權限

 

 代碼如下 復制代碼 mysql> show grants for ;   
+-------------------------------------------------------------------------------------------------------------------+
| Grants for                                                                                             |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT PROCESS, SUPER ON *.* TO IDENTIFIED BY PASSWORD '*DAFF917B80E3314B1ABECBA9DF8785AFD342CE89' |
| GRANT ALL PRIVILEGES ON `cacti`.* TO                                                               |
+-------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
 
mysql> select * from mysql.user where user='cactiuser' G 
*************************** 1. row ***************************
                 Host: %
                 User: cactiuser
             Password: *DAFF917B80E3314B1ABECBA9DF8785AFD342CE89
          Select_priv: N
          Insert_priv: N
          Update_priv: N
          Delete_priv: N
          Create_priv: N
            Drop_priv: N
          Reload_priv: N
        Shutdown_priv: N
         Process_priv: Y
            File_priv: N
           Grant_priv: N
      References_priv: N
           Index_priv: N
           Alter_priv: N
         Show_db_priv: N
           Super_priv: Y
Create_tmp_table_priv: N
     Lock_tables_priv: N
         Execute_priv: N
      Repl_slave_priv: N
     Repl_client_priv: N
     Create_view_priv: N
       Show_view_priv: N
  Create_routine_priv: N
   Alter_routine_priv: N
     Create_user_priv: N
           Event_priv: N
         Trigger_priv: N
             ssl_type:
           ssl_cipher:
          x509_issuer:
         x509_subject:
        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0

不但grants可以查看用戶權限,還可以授予MySQL用戶權限 創建、修改、刪除 MySQL 數據表結構權限哦

grant 創建、修改、刪除 MySQL 數據表結構權限。

 代碼如下 復制代碼

grant create on testdb.* to developer@'192.168.0.%';
grant alter  on testdb.* to developer@'192.168.0.%';
grant drop   on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 外鍵權限。

 代碼如下 復制代碼

grant references on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 臨時表權限。

 代碼如下 復制代碼

grant create temporary tables on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 索引權限。

grant index on  testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 視圖、查看視圖源代碼權限。

 代碼如下 復制代碼

grant create view on testdb.* to developer@'192.168.0.%';
grant show   view on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 存儲過程、函數權限。

 代碼如下 復制代碼

grant create routine on testdb.* to developer@'192.168.0.%';  -- now, can show procedure status
grant alter  routine on testdb.* to developer@'192.168.0.%';  -- now, you can drop a procedure
grant execute        on testdb.* to developer@'192.168.0.%';

copyright © 萬盛學電腦網 all rights reserved