授予用户仅查看 MySQL 视图的权限?
要授予用户仅查看 MySQL 视图的权限,请使用以下语法
GRANT SELECT ON yourDatabaseName.yourViewName TO ' yourUserName@'yourLocalHost';
首先,你需要显示表中的所有视图名称。语法如下所示 −
SHOW FULL TABLES IN yourDatabaseName WHERE TABLE_TYPE LIKE 'VIEW';
现在,实现上述语法以显示数据库中的所有视图。这里我使用数据库名称“test”。查询如下所示 −
mysql> SHOW FULL TABLES IN test WHERE TABLE_TYPE LIKE 'VIEW';
以下是输出 −
+-------------------------------+------------+ | Tables_in_test | Table_type | +-------------------------------+------------+ | empidandempname_view | VIEW | | empinfoview | VIEW | | lookuptable | VIEW | | view_student | VIEW | | viewemployeeidandemployeename | VIEW | +-------------------------------+------------+ 5 rows in set (0.00 sec)
从 MySQL.user 表中显示所有用户名和主机。查询如下所示 −
mysql> select user,host from MySQL.user;
以下是输出 −
+------------------+-----------+ | user | host | +------------------+-----------+ | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | Adam Smith | localhost | | User1 | localhost | | am | localhost | +------------------+-----------+ 9 rows in set (0.00 sec)
授予用户以及主机。现在,使用数据库“test”,视图为“viewemployeeidandemployeename”。要将其授予“Adam Smith'@'localhost”,查询如下所示 −
mysql> GRANT SELECT ON test. viewemployeeidandemployeename TO ' Adam Smith'@'localhost'; Query OK, 0 rows affected (0.18 sec)
广告