mysql grant查看用户权限命令

www.111cn.net 更新:2013-05-11 编辑:future 来源:转载
本文章来给大家总结一些常用的来查看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 webgametest@10.3.18.158;
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.%';