MySql基本操作(二)

來源:互聯網
上載者:User

標籤:mysql許可權

六、許可權

1、先建使用者,然後再授權

mysql> create user [email protected]‘localhost‘ identified by ‘[email protected]‘;

Query OK, 0 rows affected (0.22 sec)

 

mysql> show grants for ‘benet‘@‘localhost‘;

+--------------------------------------------------------------------------------------------------------------+

| Grants for [email protected] localhost                                                                                   |

+--------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘benet‘@‘ localhost ‘ IDENTIFIED BY PASSWORD ‘*760F60073FD235571A5260444301DB22136ED604‘ |

+--------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

 

mysql> grant all on benet_gbk.* to [email protected]‘ localhost ‘;

Query OK, 0 rows affected (0.22 sec)

 

mysql> show grants for ‘benet‘@‘ localhost ‘;          

+--------------------------------------------------------------------------------------------------------------+

| Grants for [email protected] localhost                                                                                   |

+--------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘benet‘@‘ localhost ‘ IDENTIFIED BY PASSWORD ‘*760F60073FD235571A5260444301DB22136ED604‘ |

| GRANT ALL PRIVILEGES ON `benet_gbk`.* TO ‘benet‘@‘ localhost ‘                                                 |

+--------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

mysql>

2、直接授權法

mysql> grant all on benet_gbk.* to [email protected]‘localhost‘ identified by ‘[email protected]‘;

Query OK, 0 rows affected (0.01 sec)

 

mysql> show grants for ‘benet1‘@‘localhos‘;

+---------------------------------------------------------------------------------------------------------------+

| Grants for [email protected]                                                                                   |

+---------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘benet1‘@‘127.0.0.1‘ IDENTIFIED BY PASSWORD ‘*760F60073FD235571A5260444301DB22136ED604‘ |

| GRANT ALL PRIVILEGES ON `benet_gbk`.* TO ‘benet1‘@‘localhos‘                                                 |

+---------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

 

3、授權bdqn使用者在192.168.1.0/24網段可以遠端連線資料庫

mysql> grant all on *.* to [email protected]‘192.168.1.%‘ identified by ‘[email protected]‘;

Query OK, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

mysql> select user,host

    -> from user;

+--------+-------------+

| user   | host        |

+--------+-------------+

| benet  | 127.0.0.1   |

| benet1 | 127.0.0.1   |

| root   | 127.0.0.1   |

| bdqn   | 192.168.1.% |

+--------+-------------+

4 rows in set (0.00 sec)

 

[[email protected] ~]# mysql -ubdqn [email protected] -h 192.168.1.101

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.38-log Source distribution

 

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

查看all許可權都包括哪些許可權,先收回一個,再查看

mysql>mysql> revoke insert on benet_gbk.* from [email protected]‘localhost‘;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show grants for [email protected]‘ localhost ‘;                   

+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Grants for [email protected] localhost                                                                                                                                                                                                         |

+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘benet‘@‘ localhost ‘ IDENTIFIED BY PASSWORD ‘*760F60073FD235571A5260444301DB22136ED604‘                                                                                                                       |

| GRANT SELECT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `benet_gbk`.* TO ‘benet‘@‘127.0.0.1‘ |

+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

 

ALL privileges許可權包括:

SELECT, INSERT,UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER

本文出自 “R博士的自由空間” 部落格,請務必保留此出處http://zhangxiaoguang.blog.51cto.com/79856/1626291

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.