MySQL查看用戶權限的兩種方法

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

MySQL查看用戶權限命令的兩方法:mysql

一. 使用MySQL grants

MySQL grant詳細用法見:http://yanue.net/post-97.html使用方法:sql

  
  
  
  
  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表示沒有權限,該用戶權限一目瞭然.這時能夠使用命令數據庫

給用戶加權限:ide

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

  
  
  
  
  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;   // 能夠看到建立表時用到的一些參數
相關文章
相關標籤/搜索