mysql的許可權管理

來源:互聯網
上載者:User

標籤:mysql

mysql的許可權授予於回收

人生最大的困難就是懶。

開始躁動起來。有關mysql的許可權授予於回收

使用者權限管理主要有以下作用:
1. 可以限制使用者訪問哪些庫、哪些表
2. 可以限制使用者對哪些表執行SELECT、CREATE、DELETE、DELETE、ALTER等操作
3. 可以限制使用者登入的IP或網域名稱
4. 可以限制使用者自己的許可權是否可以授權給別的使用者


1. 查看當前系統中的使用者

mysql> select host,user from mysql.user;+-----------+------------------+| host      | user             |+-----------+------------------+| %         | root             || %         | test             || localhost | debian-sys-maint || localhost | mysql.session    || localhost | mysql.sys        || localhost | root             |+-----------+------------------+6 rows in set (0.00 sec)

2. 授予許可權

mysql> grant all on *.* to [email protected]'%' identified by 'cmz';Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> select host,user from mysql.user;+-----------+------------------+| host      | user             |+-----------+------------------+| %         | cmz              || %         | root             || %         | test             || localhost | debian-sys-maint || localhost | mysql.session    || localhost | mysql.sys        || localhost | root             |+-----------+------------------+7 rows in set (0.00 sec)mysql> flush privileges;  # 重新整理Query OK, 0 rows affected (0.00 sec)
  • all privileges:表示將所有許可權授予給使用者。也可指定具體的許可權,如:SELECT、CREATE、DROP等。

  • on:表示這些許可權對哪些資料庫和表生效,格式:資料庫名.表名,這裡寫“*”表示所有資料庫,所有表。如果我要指定將許可權應用到test庫的user表中,可以這麼寫:test.user

  • to:將許可權授予哪個使用者。格式:”使用者名稱”@”登入IP或網域名稱”。%表示沒有限制,在任何主機都可以登入。比如:'leco'@'192.168.0.%',表示leco這個使用者只能在192.168.0 IP段登入

  • identified by:指定使用者的登入密碼

  • with grant option:表示允許使用者將自己的許可權授權給其它使用者

可以使用GRANT給使用者添加許可權,許可權會自動疊加,不會覆蓋之前授與權限,比如你先給使用者添加一個SELECT許可權,後來又給使用者添加了一個INSERT許可權,那麼該使用者就同時擁有了SELECT和INSERT許可權。

使用者詳情的許可權列表請參考MySQL官網說明:http://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html

3. 查看授與權限

mysql> show grants for cmz;+------------------------------------------+| Grants for [email protected]%                         |+------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO 'cmz'@'%' |+------------------------------------------+1 row in set (0.00 sec)

4. 回收許可權

mysql> revoke delete,create on *.* from cmz;Query OK, 0 rows affected (0.00 sec)mysql> show grants for cmz\G;*************************** 1. row ***************************Grants for [email protected]%: GRANT SELECT, INSERT, UPDATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'cmz'@'%'1 row in set (0.00 sec)ERROR: No query specified

可以見刪除和建立的許可權都沒有啦。

mysql的許可權管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.