MySQL查看使用者權限的兩種方法

來源:互聯網
上載者:User

ySQL查看使用者權限命令的兩方法:

一. 使用MySQL grants

使用方法:

 代碼如下 複製代碼

mysql> show grants for username@localhost;執行個體:

mysql> show grants for root@localhost;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.01 sec)

 二. 直接通過mysql select查詢語句:

 代碼如下 複製代碼
mysql> select * from mysql.user where user='test' and host='127.0.0.1' G;
*************************** 1. row ***************************
                  Host: 127.0.0.1
                  User: test
              Password: *EB3C643405D7F53BD4BF7FBA98DCF5641E228833
           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: N
             File_priv: N
            Grant_priv: N
       References_priv: N
            Index_priv: N
            Alter_priv: N
          Show_db_priv: N
            Super_priv: N
 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
Create_tablespace_priv: N
              ssl_type:
            ssl_cipher:
           x509_issuer:
          x509_subject:
         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string:
      password_expired: N
1 row in set (0.00 sec)

可以看到Select_priv,Insert_priv,Update_priv…等為N表示沒有許可權,該使用者權限一目瞭然.

這時可以使用命令給使用者加許可權

 

 代碼如下 複製代碼

grant all privileges on *.* to 'test'@'127.0.0.1' identified by 'passwd';
flush privileges;另外:show可以看到很多東西:

show databases;
show tables;
show create database dbname;  // 這個可以看到建立資料庫時用到的一些參數。
show create table tablename;   // 可以看到建立表時用到的一些參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.