mysql的grant权限参数汇总
很明显总共28个权限:下⾯是具体的权限介绍:转载的,记录⼀下:
⼀.权限表
mysql数据库中的3个权限表:user 、db、 host
权限表的存取过程是:
1)先从user表中的host、 user、 password这3个字段中判断连接的IP、⽤户名、密码是否存在表中,存在则通过⾝份验证;
2)通过权限验证,进⾏权限分配时,按照useràdbàtables_privàcolumns_priv的顺序进⾏分配。即先检查全局权限表user,如果user中对应的权限为Y,则此⽤户对所有数据库的权限都为Y,将不再检查db, tables_priv,columns_priv;如果为N,则到db表中检查此⽤户对应的具体数据库,并得到db中为Y的权限;如果db中为N,则检查tables_priv中此数据库对应的具体表,取得表中的权限Y,以此类推。
⼆.MySQL各种权限(共27个)
(以下操作都是以root⾝份登陆进⾏grant授权,以p1@localhost⾝份登陆执⾏各种命令。)
1. usage
连接(登陆)权限,建⽴⼀个⽤户,就会⾃动授予其usage权限(默认授予)。
mysql> grant usage on *.* to ‘p1′@’localhost’ identified by ‘123′;
该权限只能⽤于数据库登陆,不能执⾏任何操作;且usage权限不能被回收,也即REVOKE⽤户并不能删除⽤户。
2. select
必须有select的权限,才可以使⽤select table
mysql> grant select on pyt.* to ‘p1′@’localhost’;
mysql> select * from shop;
3. create
必须有create的权限,才可以使⽤create table
mysql> grant create on pyt.* to ‘p1′@’localhost’;
4. create routine
mysql面试题汇总必须具有create routine的权限,才可以使⽤{create |alter|drop} {procedure|function}
mysql> grant create routine on pyt.* to ‘p1′@’localhost’;
当授予create routine时,⾃动授予EXECUTE, ALTER ROUTINE权限给它的创建者:
mysql> show grants for ‘p1′@’localhost’;
+—————————————————————————+
Grants for p1@localhost
+————————————————————————–+
| GRANT USAGE ON *.* TO ‘p1′@’localhost’ IDENTIFIED BY PASSWORD ‘*23AE809DDACAF96AF0FD78ED04B6A265E05AA257′ | | GRANT SELECT, CREATE, CREATE ROUTINE ON `pyt`.* TO ‘p1′@’localhost’|
| GRANT EXECUTE, ALTER ROUTINE ON PROCEDURE `pyt`.`pro_shop1` TO ‘p1′@’localhost’ | +————————————————————————————-+
5. create temporary tables(注意这⾥是tables,不是table)
必须有create temporary tables的权限,才可以使⽤create temporary tables.
mysql> grant create temporary tables on pyt.* to ‘p1′@’localhost’;
[mysql@mydev ~]$ mysql -h localhost -u p1 -p pyt
mysql> create temporary table tt1(id int);
6. create view
必须有create view的权限,才可以使⽤create view
mysql> grant create view on pyt.* to ‘p1′@’localhost’;
mysql> create view v_shop as select price from shop;
7. create user
要使⽤CREATE USER,必须拥有mysql数据库的全局CREATE USER权限,或拥有INSERT权限。
mysql> grant create user on *.* to ‘p1′@’localhost’;
orm开发框架或:mysql> grant insert on *.* to p1@localhost;
8. insert
必须有insert的权限,才可以使⽤insert into ….. values….
9. alter
必须有alter的权限,才可以使⽤alter table
alter table shop modify dealer char(15);
10. alter routine
必须具有alter routine的权限,才可以使⽤{alter |drop} {procedure|function}
mysql>grant alter routine on pyt.* to ‘p1′@’ localhost ‘;
mysql> drop procedure pro_shop;
Query OK, 0 rows affected (0.00 sec)
mysql> revoke alter routine on pyt.* from ‘p1′@’localhost’;
[mysql@mydev ~]$ mysql -h localhost -u p1 -p pyt
mysql> drop procedure pro_shop;
ERROR 1370 (42000): alter routine command denied to user ‘p1′@’localhost’ for routine ‘pyt.pro_shop’
11. update
必须有update的权限,才可以使⽤update table
mysql> update shop set price=3.5 where article=0001and dealer=’A';
12. delete
必须有delete的权限,才可以使⽤delete from ….where….(删除表中的记录)
13. drop
必须有drop的权限,才可以使⽤drop database db_name; drop table tab_name;
drop view vi_name; drop index in_name;
14. show database
通过show database只能看到你拥有的某些权限的数据库,除⾮你拥有全局SHOW DATABASES权限。
对于p1@localhost⽤户来说,没有对mysql数据库的权限,所以以此⾝份登陆查询时,⽆法看到mysql数据库:mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema|
| pyt |
| test |
+——————–+
15. show view
必须拥有show view权限,才能执⾏show create view。
mysql> grant show view on pyt.* to p1@localhost;
mysql> show create view v_shop;
16. index
必须拥有index权限,才能执⾏[create |drop] index
mysql> grant index on pyt.* to p1@localhost;
mysql> create index ix_shop on shop(article);
mysql> drop index ix_shop on shop;
smart二手17. excute
执⾏存在的Functions,Procedures
mysql> call pro_shop1(0001,@a);
+———+
| article |
+———+
| 0001 |
| 0001 |
+———+
mysql> select @a;
+——+
| @a |
+——+
| 2 |
+——+
18. lock tables
必须拥有lock tables权限,才可以使⽤lock tables
mysql> grant lock tables on pyt.* to p1@localhost;
vlookup函数的含义及作用mysql> lock tables a1 read;
mysql> unlock tables;
19. references
有了REFERENCES权限,⽤户就可以将其它表的⼀个字段作为某⼀个表的外键约束。
20. reload
必须拥有reload权限,才可以执⾏flush [tables | logs | privileges]
mysql> grant reload on pyt.* to p1@localhost;
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES mysql> grant reload on *.* to ‘p1′@’localhost’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush tables;
21. replication client
拥有此权限可以查询master server、slave server状态。
mysql> show master status;
ERROR 1227 (42000): Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation
mysql> grant Replication client on *.* to p1@localhost;
或:mysql> grant super on *.* to p1@localhost;
mysql> show master status;
+——————+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+————–+——————+
| mysql-bin.000006 | 2111 | | |
+——————+———-+————–+——————+
mysql> show slave status;
22. replication slave
拥有此权限可以查看从服务器,从主服务器读取⼆进制⽇志。
mysql> show slave hosts;
ERROR 1227 (42000): Access denied; you need the REPLICATION SLAVE privilege for this operation
mysql> show binlog events;
ERROR 1227 (42000): Access denied; you need the REPLICATION SLAVE privilege for this operation
mysql> grant replication slave on *.* to p1@localhost;
mysql> show slave hosts;
Empty set (0.00 sec)
mysql>show binlog events;
+—————+——-+—————-+———–+————-+————–+
shell中读取一个文件内容| Log_name | Pos | Event_type | Server_id| End_log_pos|Info |
+—————+——-+————–+———–+————-+—————+
| mysql-bin.000005 | 4 | Format_desc | 1 | 98 | Server ver: 5.0.77-log, Binlog ver: 4 | |mysql-bin.000005|98|Query|1|197|use `mysql`; create table a1(i int)engine=myisam|……………………………
………
23. Shutdown
关闭MySQL:
[mysql@mydev ~]$ mysqladmin shutdown
二建怎么网上报名啊重新连接:
[mysql@mydev ~]$ mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
[mysql@mydev ~]$ cd /u01/mysql/bin
[mysql@mydev bin]$ ./mysqld_safe &
[mysql@mydev bin]$ mysql
24. grant option
拥有grant option,就可以将⾃⼰拥有的权限授予其他⽤户(仅限于⾃⼰已经拥有的权限)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论