MySQL查看用户权限的两种方法

http://yanue.net/post-96.html

MySQL查看用户权限命令的两方法:

一. 使用MySQL grants

MySQL grant详细用法见:http://yanue.net/post-97.html使用方法:

  1. mysql> show grants for username@localhost;
实例:
  1. mysql> show grants for root@localhost;
  2. +---------------------------------------------------------------------+
  3. | Grants for root@localhost                                           |
  4. +---------------------------------------------------------------------+
  5. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  6. +---------------------------------------------------------------------+
  7. 1 row in set (0.01 sec)

二. 直接通过mysql select查询语句:

  1. mysql> select * from mysql.user where user='test' and host='127.0.0.1' G;
  2. *************************** 1. row ***************************
  3.                   Host: 127.0.0.1
  4.                   User: test
  5.               Password: *EB3C643405D7F53BD4BF7FBA98DCF5641E228833
  6.            Select_priv: N
  7.            Insert_priv: N
  8.            Update_priv: N
  9.            Delete_priv: N
  10.            Create_priv: N
  11.              Drop_priv: N
  12.            Reload_priv: N
  13.          Shutdown_priv: N
  14.           Process_priv: N
  15.              File_priv: N
  16.             Grant_priv: N
  17.        References_priv: N
  18.             Index_priv: N
  19.             Alter_priv: N
  20.           Show_db_priv: N
  21.             Super_priv: N
  22. Create_tmp_table_priv: N
  23.       Lock_tables_priv: N
  24.           Execute_priv: N
  25.        Repl_slave_priv: N
  26.       Repl_client_priv: N
  27.       Create_view_priv: N
  28.         Show_view_priv: N
  29.    Create_routine_priv: N
  30.     Alter_routine_priv: N
  31.       Create_user_priv: N
  32.             Event_priv: N
  33.           Trigger_priv: N
  34. Create_tablespace_priv: N
  35.               ssl_type:
  36.             ssl_cipher:
  37.            x509_issuer:
  38.           x509_subject:
  39.          max_questions: 0
  40.            max_updates: 0
  41.        max_connections: 0
  42.   max_user_connections: 0
  43.                 plugin: mysql_native_password
  44. authentication_string:
  45.       password_expired: N
  46. 1 row in set (0.00 sec)

可以看到Select_priv,Insert_priv,Update_priv...等为N表示没有权限,该用户权限一目了然.这时可以使用命令

给用户加权限:

http://www.yanue.net/post-97.html

  1. grant all privileges on *.* to 'test'@'127.0.0.1' identified by 'passwd';
  2. flush privileges;
另外:show可以看到很多东西:
  1. show databases;
  2. show tables;
  3. show create database dbname;  // 这个可以看到创建数据库时用到的一些参数。
  4. show create table tablename;   // 可以看到创建表时用到的一些参数
原文地址:https://www.cnblogs.com/cqubityj/p/4939216.html