mysql用户的一些权限

mysql数据库里有3个权限表(在mysql库里):user,db,host
权限表的存储过程:
1.先从user表中的host,user,password这三个字段中判断连接的ip,用户名,密码是否存在表中,存在则通过身份验证
2.通过权限验证,进行权限分配时,按照user,db,tables_priv,columns_priv的顺序分配,即先检查全局权限表user,如果user中对应的权限为Y,则此用户对所有数据库的权限都为Y,将不再检查db,talbes_priv,columns_priv;如果为N,则到db表中检查此用户对应的具体数据库,并得到db中为Y的权限;如果db中为N,则检查tables_priv中此数据库对应的具体表,取得表中的权限Y,以此类推。

mysql的权限说明:

1.usage
该权限只能用于数据库的登录,不能执行任何操作,且普usage权限不能被回收,即REVOKE用户不能删除用户

mysql> grant usage on *.* to ‘p1′@’localhost’ identified by123′;

2.select
必须有select的权限,才可以使用select table
3.create
必须有create的权限,才可以使用create table
4. create routine
必须具有create routine的权限,才可以使用{create |alter|drop} {procedure|function}
5. create temporary tables(注意这里是tables,不是table)
必须有create temporary tables的权限,才可以使用create temporary tables.
6. create view
必须有create view的权限,才可以使用create view
7. create user
要使用CREATE USER,必须拥有mysql数据库的全局CREATE USER权限,或拥有INSERT权限。
8. insert
必须有insert的权限,才可以使用insert into ….. values….
9. alter
必须有alter的权限,才可以使用alter table
10. alter routine
必须具有alter routine的权限,才可以使用{alter |drop} {procedure|function}
11. update
必须有update的权限,才可以使用update table
12. delete
必须有delete的权限,才可以使用delete from ….where….(删除表中的记录)
13. drop
必须有drop的权限,才可以使用drop database db_name; drop table tab_name;
14. show database
通过show database只能看到你拥有的某些权限的数据库,除非你拥有全局SHOW DATABASES权限。
15. show view
必须拥有show view权限,才能执行show create view。
16. index
必须拥有index权限,才能执行[create |drop] index
17. excute
执行存在的Functions,Procedures
18. lock tables
必须拥有lock tables权限,才可以使用lock 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;

+—————+——-+—————-+———–+————-+————–+

| 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:

#没有shutdown权限时,会报错
[root@192-168-8-128 ~]# mysqladmin -utest -p'123456' shutdown 
mysqladmin: shutdown failed; error: 'Access denied; you need (at least one of) the SHUTDOWN privilege(s) for this operation'
#添加shutdown权限
mysql>GRANT shutdown ON *.* TO 'test'@'localhost' IDENTIFIED BY '123456';
#再次执行,不报错,关闭mysql成功
[root@192-168-8-128 ~]# mysqladmin -utest -p -S /home/mysql/mysql.sock shutdown
Enter password: 
[root@192-168-8-128 ~]#

24. grant option
拥有grant option,就可以将自己拥有的权限授予其他用户(仅限于自己已经拥有的权限)
25. file
拥有file权限才可以执行 select ..into outfile和load data infile…操作,但是不要把file, process, super权限授予管理员以外的账号,这样存在严重的安全隐患。
26. super
这个权限允许用户终止任何查询;修改全局变量的SET语句;使用CHANGE MASTER,PURGE MASTER LOGS。
27. process
通过这个权限,用户可以执行SHOW PROCESSLIST和KILL命令。默认情况下,每个用户都可以执行SHOW PROCESSLIST命令,但是只能查询本用户的进程。
另外
管理权限(如 super, process, file等)不能够指定某个数据库,on后面必须跟.

mysql> grant super on pyt.* to p1@localhost;
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
mysql> grant super on *.* to p1@localhost;
Query OK, 0 rows affected (0.01 sec)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章