0
点赞
收藏
分享

微信扫一扫

ruoyi菜单折叠,菜单收缩

ixiaoyang8 2023-09-27 阅读 33
mysql

MySQL权限管理grant:

权限说明:

Table 6.2 Permissible Privileges for GRANT and REVOKE

PrivilegeGrant Table ColumnContext
ALL [PRIVILEGES]Synonym for “all privileges”Server administration
ALTERAlter_privTables
ALTER ROUTINEAlter_routine_privStored routines
CREATECreate_privDatabases, tables, or indexes
CREATE ROUTINECreate_routine_privStored routines
CREATE TABLESPACECreate_tablespace_privServer administration
CREATE TEMPORARY TABLESCreate_tmp_table_privTables
CREATE USERCreate_user_privServer administration
CREATE VIEWCreate_view_privViews
DELETEDelete_privTables
DROPDrop_privDatabases, tables, or views
EVENTEvent_privDatabases
EXECUTEExecute_privStored routines
FILEFile_privFile access on server host
GRANT OPTIONGrant_privDatabases, tables, or stored routines
INDEXIndex_privTables
INSERTInsert_privTables or columns
LOCK TABLESLock_tables_privDatabases
PROCESSProcess_privServer administration
PROXYSee proxies_priv tableServer administration
REFERENCESReferences_privDatabases or tables
RELOADReload_privServer administration
REPLICATION CLIENTRepl_client_privServer administration
REPLICATION SLAVERepl_slave_privServer administration
SELECTSelect_privTables or columns
SHOW DATABASESShow_db_privServer administration
SHOW VIEWShow_view_privViews
SHUTDOWNShutdown_privServer administration
SUPERSuper_privServer administration
TRIGGERTrigger_privTables
UPDATEUpdate_privTables or columns
USAGESynonym for “no privileges”Server administration

说明:

USAGE:无权限,只有登录数据库,只可以使用test和test_*数据库。

ALL: 所有权限。

以下权限为指定权限。

select/update/delete/supper/replication slave/reload ...

with grant option: 选项表示允许把自己的权限授予其他用户或者从其他用户收回自己的权限。

默认情况下,分配权限时如果没有指定with grant option,代表这个用户不能下发权限给其他用户,但是这个权限不能超过自己的权限。

权限的保存位置:(了解):

给用户授权:

基本语法:

mysql> grant 权限1,权限2 on 库.表 to 用户@主机
mysql> grant 权限(列1,列2,...) on 库.表 to 用户@主机

库.表表示方法:*.*代表所有数据库的所有数据表,db_itheima.*代表db_itheima数据库中的所有数据表,db_itheima.tb_admin,代表db_itheima数据库中的tb_admin表

*:通配符。

案例:给tom账号分配db_db3库的查询(select)权限:

mysql> grant select on db_db3.* to 'tom'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> show grants for 'tom'@'localhost';
+-------------------------------------------------+
| Grants for tom@localhost                        |
+-------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'localhost'         |
| GRANT SELECT ON `db_db3`.* TO 'tom'@'localhost' |
+-------------------------------------------------+
2 rows in set (0.00 sec)

案例:给tom账号分配db_db3数据表的权限(要求只能更改age权限。)

该案例是具体到某个列。

mysql> grant update(age) on db_db3.tb_student to 'tom'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)


mysql> show grants for 'tom'@'localhost';
+------------------------------------------------------------------+
| Grants for tom@localhost                                         |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'localhost'                          |
| GRANT SELECT ON `db_db3`.* TO 'tom'@'localhost'                  |
| GRANT UPDATE (age) ON `db_db3`.`tb_student` TO 'tom'@'localhost' |
+------------------------------------------------------------------+
3 rows in set (0.00 sec)

举报

相关推荐

0 条评论