如何查看mysql的使用者及授權

來源:互聯網
上載者:User

標籤:mysql 許可權

1)查看mysql中存在的使用者

mysql> select user,host from mysql.user;+------------+--------------------------+| user       | host                     |+------------+--------------------------+| oldgirl    | %                        || wan        | %                        || wanlong    | %                        || rep        | 10.10.10.%               || root       | 10.10.10.%               || wan        | 10.10.10.%               || wanlong    | 10.10.10.%               || oldgril123 | 10.10.10.0/255.255.255.0 || root       | 127.0.0.1                || root       | ::1                      || root       | C67-X64-A8               || backup     | localhost                || root       | localhost                |+------------+--------------------------+13 rows in set (0.00 sec)

2)如何查看使用者的授權

mysql> show grants for ‘wanlong‘@‘10.10.10.%‘;+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Grants for [email protected]%                                                                                                                                                                                                                                                                                                                              |+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| GRANT SELECT, UPDATE, DELETE, CREATE, 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 ‘wanlong‘@‘10.10.10.%‘ |+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)

3)all privileges具備哪些許可權


a、建立測試帳號並進行授權:

mysql> create user wanlong identified by ‘wanlong‘;Query OK, 0 rows affected (0.01 sec)mysql> grant all privileges on *.* to ‘wanlong‘@‘10.10.10.%‘;Query OK, 0 rows affected (0.00 sec)mysql> show grants for ‘wanlong‘@‘10.10.10.%‘;+-------------------------------------------------------+| Grants for [email protected]%                         |+-------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO ‘wanlong‘@‘10.10.10.%‘ |+-------------------------------------------------------+1 row in set (0.00 sec)

b、回收insert許可權,並查看使用者的許可權

mysql> revoke insert on *.* from ‘wanlong‘@‘10.10.10.%‘;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)mysql> show grants for ‘wanlong‘@‘10.10.10.%‘;+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Grants for [email protected]%                                                                                                                                                                                                                                                                                                                              |+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| GRANT SELECT, UPDATE, DELETE, CREATE, 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 ‘wanlong‘@‘10.10.10.%‘ |+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)

c、匯出檔案,並查看授權(all privileges還需要添加剛才使用revoke取消的insert授權)

# mysql -uroot -predhat12345 -S /data/3306/mysql.sock -e "show grants for ‘wanlong‘@‘10.10.10.%‘;"|grep -i grant|tail -1|tr ‘,‘ ‘\n‘>all.privileges查看all privileges具備的許可權:# cat all.privileges GRANT SELECT UPDATE DELETE CREATE 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 ‘wanlong‘@‘10.10.10.%‘

本文出自 “冰凍vs西瓜” 部落格,請務必保留此出處http://molewan.blog.51cto.com/287340/1861834

如何查看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.