一个用户有下面的权限:
mysql>SHOW GRANTS FOR jsmith;+----------------------------------------------------------------------+
| Grants for jsmith@% |
+----------------------------------------------------------------------+
| GRANT USAGE ON * * TO 'jsmith'@'%' |
| GRANT UPDATE (Name) ON 'world'.country' TO 'jsmith'@'%'; |
+----------------------------------------------------------------------+
2 rows in set(0.00sec)
jsmith可以执行哪两条SQL语句?
A)UPDATE world.country SET Name='all;
B)UPDATE world.Country SET Name=‘new’ WHERE Name='old;
C)UPDATE world.country SET Name=‘one’ LIMIT1;
D)UPDATE world.country SET Name=‘first’ ORDER BY Name LIMIT 1;
E)UPDATE world.country SET Name=CONCAT(‘New’,Name);
我们看到这个用户的权限非常小,他只有两个权限,第一个权限是能登录MySQL数据库,第二个权限是对world.country表的name字段有update权限。
为了正确回答这道题目,我们先看一个例子。
mysql> show grants;
+------------------------------------------------------------------+
| Grants for yaoyuan@% |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `yaoyuan`@`%` |
| GRANT SELECT (`first_name`) ON `sakila`.`actor` TO `yaoyuan`@`%` |
+------------------------------------------------------------------+
2 rows in set (0.00 sec)
这里的用户只有对first_name字段的select权限,当然这个用户可以查询first_name ,不能查询字段last_name 。
mysql> select first_name from actor limit 1;
+------------+
| first_name |
+------------+
| PENELOPE |
+------------+
1 row in set (0.00 sec)mysql> select first_name,last_name from actor limit 1;
ERROR 1143 (42000): SELECT command denied to user 'yaoyuan'@'localhost' for column 'last_name' in table 'actor'
我们再扩展看看如果last_name在where子句中做为条件过滤,可以吗?
mysql> select first_name from actor where last_name='a' limit 1;
ERROR 1143 (42000): SELECT command denied to user 'yaoyuan'@'localhost' for column 'last_name' in table 'actor'
通过实验,我们发现在在where子句中做为条件过滤的字段也需要用户对它有select权限才行。再看看用last_name 字段排序是否可以?
mysql> select first_name from actor order by last_name limit 1;
ERROR 1143 (42000): SELECT command denied to user 'yaoyuan'@'localhost' for column 'last_name' in table 'actor'
通过实验,发现也不行。
同样的道理,CONCAT函数中的字段也要有select权限才行,
因此这个题目正确的答案是A和C,您答对了吗?更多关于MySQL OCP和ORACLE OCP考试下资料请参看下面的视频。
Oracle 19c OCP和MySQL 8.0 OCP应试指南和题库讲解