host 列: %,localhost,127.0.0.1,::1 1)授权普通用户,具有查询、插入、更新、删除 itpux 这个数据库所有表数据的权限。 grant select, insert, update, delete on itpux.* to itpux1@'%'; flush privileges; show grants for itpux1@'%' 2)开发人员授权:创建/删除/修改-表/索引/视图/存储过程/函数等权限 create user dev@'%' identified by 'dev'; grant create,alter,drop on itpux1.* to dev@'%'; flush privileges; show grants for dev@'%'; create user dev@'10.0.0.%' identified by 'dev'; grant create,alter,drop on itpux1.* to dev@'10.0.0.%'; flush privileges; show grant for dev@'10.0.0.%'; 3)操作mysql外键的权限 grant references on itpux1.* to dev@'%'; flush privileges; 4)操作mysql临时表的权限 grant create temporary tables on itpux1.* to dev@'%'; flush privileges; 5)操作mysql索引的权限 grant index on itpux1.* to dev@'%'; flush privileges; 6)操作mysql视图的权限 grant create view,show view on itpux1.* to dev@'%'; flush privileges; 7)操作mysql存储过程/函数的权限 grant create routine,alter routine,execute on itpux1.* to dev@'%'; 8)授权一个普通的dba用户,可以管理某一个数据库 grant all privileges on itpux to itpuxdba@'localhost' identified by 'itpuxdba'; flush privileges; 9)授权一个高级的dba用户,可以管理所有的数据库 grant all privileges on *.* to alldba@'localhost' identified by 'alldba'; flush privileges; 10)授权针对所有的数据库 grant all privileges on *.* to alldba@'localhost'; flush privileges; 11)授权针对单个的数据库 grant all privileges on itpux to alldbae'LocaLhost'i grant select on itpux.* to alldba@'localhost'; flush privileges; 12)授权针对所有的数据库 grant select on itpux.* to alldba@'locaLhost'; flush privileges; 13)授权针对单个列 grant select(deptno,dname) on itpux.dept to alldba@'localhost'; flush privileges; 14)授权针对存储过程和函数 grant execute on procedure 库名.过程名 to alldba@'localhost'; grant execute on function 库名.函数名 to alldba@'localhost'; flush privileges;
1)授权针对所有的数据库 revoke revoke all privileges on *.* from alldba@'localhost'; flush privileges; 2)授权针对单个的数据库 revoke all privileges on itpux.* from alldba@'locaLhost'; revoke select on itpux.* from alldba@'localhost'; flush privileges; 3)授权针对所有的数据库 revoke select on itpux.* from alldba@'locaLhost'; flush privileges; 4)授权针对单个列 revoke select(deptno,dname) on itpux.dept from alldba@'localhost'; flush privileges; 5)授权针对存储过程和函数 revoke execute on procedure 库名.过程名 from alldba@'localhost'; revoke execute on function 库名.函数名 from alldba@'localhost'; flush privileges; show grants for alldba@'localhost' show grants for itpux1@'localhost'
另类方法:直接修改授权表回收授权-不建议使用
select user,host from mysql.user delete from mysql.user where user='alldba' and host='localhost'; commit; flush privileges; select user,host from mysql.user;
select user,host from mysql.user; drop user dev; drop user dev@'%'; drop user dev@'192.168.1.%'; select user,host from mysql.user where user like 'dev%'; select user,host from mysql.user; rename user 'itpuxdba'@'localhost' to 'itpuxdba1'@'localhost';
show grants for itpux; show grants for itpux@localhost; select * from mysql.user where user='itpux1' and host='localhost'; select CURRENT_USER(); show grants; show grants for current_user; mysql root@localhost:mysql> show grants for current_user\G ***************************[ 1. row ]*************************** Grants for root@localhost | GRANT SELECT, INSERT, 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, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION ***************************[ 2. row ]*************************** Grants for root@localhost | GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN, GROUP_REPLICATION_ADMIN,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN, SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,XA_RECOVER_ADMIN ON *.* TO `root`@`localhost` WITH GRANT OPTION ***************************[ 3. row ]*************************** Grants for root@localhost | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION