用户权限

mysql的user表中保存一些权限信息,那是用户的操作权限,比如说select,delete,update等权限。但是刚创建的用户是没有操作其他已经存在数据库及表的权限,需要其他高级用户分配权限
给userName用户操作dbname数据库所有表的权限。

注意:要授权的用户,必须有授权的权限,还必须拥有你将要授予其他用户权限的所有权限

1. 给用户授予权限

给用户授予权限的一般语法,下面的语法不全。有兴趣可以自己查看使用help grant命令

GRANT
    priv_type  ON [object_type] priv_level
    TO user [auth_option]  ...

priv_type:{//常用的权限类型
	select,
	update,
	delete,
	insert,
	ALL,
	......
}

object_type: { //对象类型
    TABLE
  | FUNCTION
  | PROCEDURE
}

priv_level: { // 权限范围
    *
  | *.*
  | db_name.*
  | db_name.tbl_name
  | tbl_name
  | db_name.routine_name
}

user: //账户
    'username'@'host'

示例:

  1. 授予所有权限

    GRANT ALL ON test.* TO 'userName'@'host' 
    
  2. 授予’test1’ select 权限

    GRANT select ON test.* TO 'test1' 
    
2.查询用户权限
show grants for '用户名'@'主机名'

没有任何权限的用户“test1”

show grants for 'test1'
Grants for test1@%
GRANT USAGE ON . TO ‘test1’@’%’

USAGE 就是没有权限

MySQL中的权限
权限解释 和授权等级
ALL[PRIVILEGES] Grant all privileges at specified access level except GRANT OPTION and PROXY.
ALTER修改表的权限 . Levels: Global, database, table.
ALTER ROUTINEEnable stored routines to be altered or dropped. Levels: Global, database, routine.
CREATE创建表或者数据库的权限。 Levels: Global, database, table.
CREATE ROUTINEEnable stored routine creation. Levels: Global, database.
CREATE TABLESPACEEnable tablespaces and log file groups to be created, altered, or dropped. Level: Global.
CREATE TEMPORARY TABLESEnable use of CREATE TEMPORARY TABLE. Levels: Global, database.
CREATE USEREnable use of CREATE USER, DROP USER, RENAME USER, and REVOKE ALL PRIVILEGES. Level: Global.
CREATE VIEW创建或者修改试图的权限 Levels: Global, database, table.
DELETE删除数据库或者表的权限. Level: Global, database, table.
DROP删除数据库,表或者试图的权限. Levels: Global, database, table.
EVENTEnable use of events for the Event Scheduler. Levels: Global, database.
EXECUTEEnable the user to execute stored routines. Levels: Global, database, routine.
FILEEnable the user to cause the server to read or write files. Level: Global.
GRANT OPTION允许给其他账号授权或者取消授权 . Levels: Global, database, table, routine, proxy.
INDEXEnable indexes to be created or dropped. Levels: Global, database, table.
INSERT使用insert的 权限. Levels: Global, database, table, column.
LOCK TABLESEnable use of LOCK TABLES on tables for which you have the SELECT privilege. Levels: Global, database.
PROCESSEnable the user to see all processes with SHOW PROCESSLIST. Level: Global.
PROXYEnable user proxying. Level: From user to user.
REFERENCESEnable foreign key creation. Levels: Global, database, table, column.
RELOADEnable use of FLUSH operations. Level: Global.
REPLICATION CLIENTEnable the user to ask where master or slave servers are. Level: Global.
REPLICATION SLAVEEnable replication slaves to read binary log events from the master. Level: Global.
SELECT使用select 查询的权限 Levels: Global, database, table, column.
SHOW DATABASES可以使用 SHOW DATABASES 命令显示所有数据库的权限. Level: Global.
SHOW VIEW使用SHOW CREATE VIEW显示所有试图的权限. Levels: Global, database, table.
SHUTDOWNEnable use of mysqladmin shutdown. Level: Global.
SUPEREnable use of other administrative operations such as CHANGE MASTER TO, KILL, PURGE BINARY LOGS, SET GLOBAL, and mysqladmin debug command. Level: Global.
TRIGGEREnable trigger operations. Levels: Global, database, table.
UPDATEEnable use of UPDATE. Levels: Global, database, table, column.
USAGE“no privileges”的同义词
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐