mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / r / view_grant.result
blob27b6bc9e6f7eb1dd668fd3de3b9b26005e409640
1 drop database if exists mysqltest;
2 drop view if exists v1,v2,v3;
3 grant create view on test.* to test@localhost;
4 show grants for test@localhost;
5 Grants for test@localhost
6 GRANT USAGE ON *.* TO 'test'@'localhost'
7 GRANT CREATE VIEW ON `test`.* TO 'test'@'localhost'
8 revoke create view on test.* from test@localhost;
9 show grants for test@localhost;
10 Grants for test@localhost
11 GRANT USAGE ON *.* TO 'test'@'localhost'
12 drop user test@localhost;
13 create database mysqltest;
14 create table mysqltest.t1 (a int, b int);
15 create table mysqltest.t2 (a int, b int);
16 grant select on mysqltest.t1 to mysqltest_1@localhost;
17 grant create view,select on test.* to mysqltest_1@localhost;
18 create definer=root@localhost view v1 as select * from mysqltest.t1;
19 ERROR 42000: Access denied; you need the SUPER privilege for this operation
20 create view v1 as select * from mysqltest.t1;
21 alter view v1 as select * from mysqltest.t1;
22 ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table 'v1'
23 create or replace view v1 as select * from mysqltest.t1;
24 ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table 'v1'
25 create view mysqltest.v2  as select * from mysqltest.t1;
26 ERROR 42000: CREATE VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v2'
27 create view v2 as select * from mysqltest.t2;
28 ERROR 42000: ANY command denied to user 'mysqltest_1'@'localhost' for table 't2'
29 show create view v1;
30 View    Create View     character_set_client    collation_connection
31 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`mysqltest_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `mysqltest`.`t1`.`a` AS `a`,`mysqltest`.`t1`.`b` AS `b` from `mysqltest`.`t1`     latin1  latin1_swedish_ci
32 grant create view,drop,select on test.* to mysqltest_1@localhost;
33 use test;
34 alter view v1 as select * from mysqltest.t1;
35 create or replace view v1 as select * from mysqltest.t1;
36 revoke all privileges on mysqltest.t1 from mysqltest_1@localhost;
37 revoke all privileges on test.* from mysqltest_1@localhost;
38 drop database mysqltest;
39 drop view test.v1;
40 create database mysqltest;
41 create table mysqltest.t1 (a int, b int);
42 create view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1;
43 grant select (c) on mysqltest.v1 to mysqltest_1@localhost;
44 select c from mysqltest.v1;
46 select d from mysqltest.v1;
47 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 'v1'
48 revoke all privileges on mysqltest.v1 from mysqltest_1@localhost;
49 delete from mysql.user where user='mysqltest_1';
50 drop database mysqltest;
51 create database mysqltest;
52 create table mysqltest.t1 (a int, b int);
53 create algorithm=temptable view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1;
54 grant select (c) on mysqltest.v1 to mysqltest_1@localhost;
55 select c from mysqltest.v1;
57 select d from mysqltest.v1;
58 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'd' in table 'v1'
59 revoke all privileges on mysqltest.v1 from mysqltest_1@localhost;
60 delete from mysql.user where user='mysqltest_1';
61 drop database mysqltest;
62 create database mysqltest;
63 create table mysqltest.t1 (a int, b int);
64 create table mysqltest.t2 (a int, b int);
65 create view mysqltest.v1 (c,d) as select a+1,b+1 from mysqltest.t1;
66 create algorithm=temptable view mysqltest.v2 (c,d) as select a+1,b+1 from mysqltest.t1;
67 create view mysqltest.v3 (c,d) as select a+1,b+1 from mysqltest.t2;
68 create algorithm=temptable view mysqltest.v4 (c,d) as select a+1,b+1 from mysqltest.t2;
69 create view mysqltest.v5 (c,d) as select a+1,b+1 from mysqltest.t1;
70 grant select on mysqltest.v1 to mysqltest_1@localhost;
71 grant select on mysqltest.v2 to mysqltest_1@localhost;
72 grant select on mysqltest.v3 to mysqltest_1@localhost;
73 grant select on mysqltest.v4 to mysqltest_1@localhost;
74 grant show view on mysqltest.v5 to mysqltest_1@localhost;
75 select c from mysqltest.v1;
77 select c from mysqltest.v2;
79 select c from mysqltest.v3;
81 select c from mysqltest.v4;
83 select c from mysqltest.v5;
84 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'v5'
85 show columns from mysqltest.v1;
86 Field   Type    Null    Key     Default Extra
87 c       bigint(12)      YES             NULL    
88 d       bigint(12)      YES             NULL    
89 show columns from mysqltest.v2;
90 Field   Type    Null    Key     Default Extra
91 c       bigint(12)      YES             NULL    
92 d       bigint(12)      YES             NULL    
93 explain select c from mysqltest.v1;
94 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
95 show create view mysqltest.v1;
96 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v1'
97 explain select c from mysqltest.v2;
98 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
99 show create view mysqltest.v2;
100 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v2'
101 explain select c from mysqltest.v3;
102 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
103 show create view mysqltest.v3;
104 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v3'
105 explain select c from mysqltest.v4;
106 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
107 show create view mysqltest.v4;
108 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v4'
109 explain select c from mysqltest.v5;
110 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'v5'
111 show create view mysqltest.v5;
112 View    Create View     character_set_client    collation_connection
113 v5      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v5` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`    latin1  latin1_swedish_ci
114 explain select c from mysqltest.v1;
115 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
116 show create view mysqltest.v1;
117 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v1'
118 grant show view on mysqltest.v1 to mysqltest_1@localhost;
119 grant select on mysqltest.t1 to mysqltest_1@localhost;
120 explain select c from mysqltest.v1;
121 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
122 1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    0       const row not found
123 show create view mysqltest.v1;
124 View    Create View     character_set_client    collation_connection
125 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`    latin1  latin1_swedish_ci
126 explain select c from mysqltest.v2;
127 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
128 show create view mysqltest.v2;
129 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v2'
130 explain select c from mysqltest.v3;
131 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
132 show create view mysqltest.v3;
133 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v3'
134 explain select c from mysqltest.v4;
135 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
136 show create view mysqltest.v4;
137 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v4'
138 explain select c from mysqltest.v5;
139 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'v5'
140 show create view mysqltest.v5;
141 View    Create View     character_set_client    collation_connection
142 v5      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v5` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`    latin1  latin1_swedish_ci
143 grant show view on mysqltest.* to mysqltest_1@localhost;
144 explain select c from mysqltest.v1;
145 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
146 1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    0       const row not found
147 show create view mysqltest.v1;
148 View    Create View     character_set_client    collation_connection
149 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`    latin1  latin1_swedish_ci
150 explain select c from mysqltest.v2;
151 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
152 1       PRIMARY <derived2>      system  NULL    NULL    NULL    NULL    0       const row not found
153 2       DERIVED NULL    NULL    NULL    NULL    NULL    NULL    NULL    no matching row in const table
154 show create view mysqltest.v2;
155 View    Create View     character_set_client    collation_connection
156 v2      CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`    latin1  latin1_swedish_ci
157 explain select c from mysqltest.v3;
158 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
159 show create view mysqltest.v3;
160 View    Create View     character_set_client    collation_connection
161 v3      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v3` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`    latin1  latin1_swedish_ci
162 explain select c from mysqltest.v4;
163 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
164 show create view mysqltest.v4;
165 View    Create View     character_set_client    collation_connection
166 v4      CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest`.`v4` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`    latin1  latin1_swedish_ci
167 revoke all privileges on mysqltest.* from mysqltest_1@localhost;
168 delete from mysql.user where user='mysqltest_1';
169 drop database mysqltest;
170 create database mysqltest;
171 create table mysqltest.t1 (a int, b int, primary key(a));
172 insert into mysqltest.t1 values (10,2), (20,3), (30,4), (40,5), (50,10);
173 create table mysqltest.t2 (x int);
174 insert into mysqltest.t2 values (3), (4), (5), (6);
175 create view mysqltest.v1 (a,c) as select a, b+1 from mysqltest.t1;
176 create view mysqltest.v2 (a,c) as select a, b from mysqltest.t1;
177 create view mysqltest.v3 (a,c) as select a, b+1 from mysqltest.t1;
178 grant update (a) on mysqltest.v2 to mysqltest_1@localhost;
179 grant update on mysqltest.v1 to mysqltest_1@localhost;
180 grant select on mysqltest.* to mysqltest_1@localhost;
181 use mysqltest;
182 update t2,v1 set v1.a=v1.a+v1.c where t2.x=v1.c;
183 select * from t1;
184 a       b
185 13      2
186 24      3
187 35      4
188 46      5
189 50      10
190 update v1 set a=a+c;
191 select * from t1;
192 a       b
193 16      2
194 28      3
195 40      4
196 52      5
197 61      10
198 update t2,v2 set v2.a=v2.a+v2.c where t2.x=v2.c;
199 select * from t1;
200 a       b
201 16      2
202 31      3
203 44      4
204 57      5
205 61      10
206 update v2 set a=a+c;
207 select * from t1;
208 a       b
209 18      2
210 34      3
211 48      4
212 62      5
213 71      10
214 update t2,v2 set v2.c=v2.a+v2.c where t2.x=v2.c;
215 ERROR 42000: UPDATE command denied to user 'mysqltest_1'@'localhost' for column 'c' in table 'v2'
216 update v2 set c=a+c;
217 ERROR 42000: UPDATE command denied to user 'mysqltest_1'@'localhost' for column 'c' in table 'v2'
218 update t2,v3 set v3.a=v3.a+v3.c where t2.x=v3.c;
219 ERROR 42000: UPDATE command denied to user 'mysqltest_1'@'localhost' for table 'v3'
220 update v3 set a=a+c;
221 ERROR 42000: UPDATE command denied to user 'mysqltest_1'@'localhost' for table 'v3'
222 use test;
223 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
224 drop database mysqltest;
225 create database mysqltest;
226 create table mysqltest.t1 (a int, b int, primary key(a));
227 insert into mysqltest.t1 values (1,2), (2,3), (3,4), (4,5), (5,10);
228 create table mysqltest.t2 (x int);
229 insert into mysqltest.t2 values (3), (4), (5), (6);
230 create view mysqltest.v1 (a,c) as select a, b+1 from mysqltest.t1;
231 create view mysqltest.v2 (a,c) as select a, b+1 from mysqltest.t1;
232 grant delete on mysqltest.v1 to mysqltest_1@localhost;
233 grant select on mysqltest.* to mysqltest_1@localhost;
234 use mysqltest;
235 delete from v1 where c < 4;
236 select * from t1;
237 a       b
238 2       3
239 3       4
240 4       5
241 5       10
242 delete v1 from t2,v1 where t2.x=v1.c;
243 select * from t1;
244 a       b
245 5       10
246 delete v2 from t2,v2 where t2.x=v2.c;
247 ERROR 42000: DELETE command denied to user 'mysqltest_1'@'localhost' for table 'v2'
248 delete from v2 where c < 4;
249 ERROR 42000: DELETE command denied to user 'mysqltest_1'@'localhost' for table 'v2'
250 use test;
251 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
252 drop database mysqltest;
253 create database mysqltest;
254 create table mysqltest.t1 (a int, b int, primary key(a));
255 insert into mysqltest.t1 values (1,2), (2,3);
256 create table mysqltest.t2 (x int, y int);
257 insert into mysqltest.t2 values (3,4);
258 create view mysqltest.v1 (a,c) as select a, b from mysqltest.t1;
259 create view mysqltest.v2 (a,c) as select a, b from mysqltest.t1;
260 grant insert on mysqltest.v1 to mysqltest_1@localhost;
261 grant select on mysqltest.* to mysqltest_1@localhost;
262 use mysqltest;
263 insert into v1 values (5,6);
264 select * from t1;
265 a       b
266 1       2
267 2       3
268 5       6
269 insert into v1 select x,y from t2;
270 select * from t1;
271 a       b
272 1       2
273 2       3
274 5       6
275 3       4
276 insert into v2 values (5,6);
277 ERROR 42000: INSERT command denied to user 'mysqltest_1'@'localhost' for table 'v2'
278 insert into v2 select x,y from t2;
279 ERROR 42000: INSERT command denied to user 'mysqltest_1'@'localhost' for table 'v2'
280 use test;
281 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
282 drop database mysqltest;
283 create database mysqltest;
284 create table mysqltest.t1 (a int, b int);
285 create table mysqltest.t2 (a int, b int);
286 grant update on mysqltest.t1 to mysqltest_1@localhost;
287 grant update(b) on mysqltest.t2 to mysqltest_1@localhost;
288 grant create view,update on test.* to mysqltest_1@localhost;
289 create view v1 as select * from mysqltest.t1;
290 create view v2 as select b from mysqltest.t2;
291 create view mysqltest.v1 as select * from mysqltest.t1;
292 ERROR 42000: CREATE VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v1'
293 create view v3 as select a from mysqltest.t2;
294 ERROR 42000: ANY command denied to user 'mysqltest_1'@'localhost' for column 'a' in table 't2'
295 create table mysqltest.v3 (b int);
296 grant create view on mysqltest.v3 to mysqltest_1@localhost;
297 drop table mysqltest.v3;
298 create view mysqltest.v3 as select b from mysqltest.t2;
299 grant create view, update on mysqltest.v3 to mysqltest_1@localhost;
300 drop view mysqltest.v3;
301 create view mysqltest.v3 as select b from mysqltest.t2;
302 create view v4 as select b+1 from mysqltest.t2;
303 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'b' in table 't2'
304 grant create view,update,select on test.* to mysqltest_1@localhost;
305 create view v4 as select b+1 from mysqltest.t2;
306 ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'b' in table 't2'
307 grant update,select(b) on mysqltest.t2 to mysqltest_1@localhost;
308 create view v4 as select b+1 from mysqltest.t2;
309 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
310 drop database mysqltest;
311 drop view v1,v2,v4;
312 create database mysqltest;
313 create table mysqltest.t1 (a int);
314 grant all privileges on mysqltest.* to mysqltest_1@localhost;
315 use mysqltest;
316 create view v1 as select * from t1;
317 use test;
318 revoke all privileges on mysqltest.* from mysqltest_1@localhost;
319 drop database mysqltest;
320 create database mysqltest;
321 create table mysqltest.t1 (a int, b int);
322 grant select on mysqltest.t1 to mysqltest_1@localhost;
323 grant create view,select on test.* to mysqltest_1@localhost;
324 create view v1 as select * from mysqltest.t1;
325 show create view v1;
326 View    Create View     character_set_client    collation_connection
327 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`mysqltest_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `mysqltest`.`t1`.`a` AS `a`,`mysqltest`.`t1`.`b` AS `b` from `mysqltest`.`t1`     latin1  latin1_swedish_ci
328 revoke select on mysqltest.t1 from mysqltest_1@localhost;
329 select * from v1;
330 ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
331 grant select on mysqltest.t1 to mysqltest_1@localhost;
332 select * from v1;
333 a       b
334 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
335 drop view v1;
336 drop database mysqltest;
337 create database mysqltest;
338 use mysqltest;
339 create table t1 (a int);
340 insert into t1 values (1);
341 create table t2 (s1 int);
342 drop function if exists f2;
343 create function f2 () returns int begin declare v int; select s1 from t2
344 into v; return v; end//
345 create algorithm=TEMPTABLE view v1 as select f2() from t1;
346 create algorithm=MERGE view v2 as select f2() from t1;
347 create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select f2() from t1;
348 create algorithm=MERGE SQL SECURITY INVOKER view v4 as select f2() from t1;
349 create SQL SECURITY INVOKER view v5 as select * from v4;
350 grant select on v1 to mysqltest_1@localhost;
351 grant select on v2 to mysqltest_1@localhost;
352 grant select on v3 to mysqltest_1@localhost;
353 grant select on v4 to mysqltest_1@localhost;
354 grant select on v5 to mysqltest_1@localhost;
355 use mysqltest;
356 select * from v1;
357 f2()
358 NULL
359 Warnings:
360 Warning 1329    No data - zero rows fetched, selected, or processed
361 select * from v2;
362 f2()
363 NULL
364 Warnings:
365 Warning 1329    No data - zero rows fetched, selected, or processed
366 select * from v3;
367 ERROR HY000: View 'mysqltest.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
368 select * from v4;
369 ERROR HY000: View 'mysqltest.v4' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
370 select * from v5;
371 ERROR HY000: View 'mysqltest.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
372 use test;
373 drop view v1, v2, v3, v4, v5;
374 drop function f2;
375 drop table t1, t2;
376 use test;
377 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
378 drop database mysqltest;
379 create database mysqltest;
380 use mysqltest;
381 create table t1 (a int);
382 insert into t1 values (1);
383 create table t2 (s1 int);
384 drop function if exists f2;
385 create function f2 () returns int begin declare v int; select s1 from t2
386 into v; return v; end//
387 grant select on t1 to mysqltest_1@localhost;
388 grant execute on function f2 to mysqltest_1@localhost;
389 grant create view on mysqltest.* to mysqltest_1@localhost;
390 use mysqltest;
391 create algorithm=TEMPTABLE view v1 as select f2() from t1;
392 create algorithm=MERGE view v2 as select f2() from t1;
393 create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select f2() from t1;
394 create algorithm=MERGE SQL SECURITY INVOKER view v4 as select f2() from t1;
395 use test;
396 create view v5 as select * from v1;
397 revoke execute on function f2 from mysqltest_1@localhost;
398 select * from v1;
399 ERROR HY000: View 'mysqltest.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
400 select * from v2;
401 ERROR HY000: View 'mysqltest.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
402 select * from v3;
403 f2()
404 NULL
405 Warnings:
406 Warning 1329    No data - zero rows fetched, selected, or processed
407 select * from v4;
408 f2()
409 NULL
410 Warnings:
411 Warning 1329    No data - zero rows fetched, selected, or processed
412 select * from v5;
413 ERROR HY000: View 'mysqltest.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
414 drop view v1, v2, v3, v4, v5;
415 drop function f2;
416 drop table t1, t2;
417 use test;
418 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
419 drop database mysqltest;
420 create database mysqltest;
421 use mysqltest;
422 create table t1 (a int);
423 create table v1 (a int);
424 insert into t1 values (1);
425 grant select on t1 to mysqltest_1@localhost;
426 grant select on v1 to mysqltest_1@localhost;
427 grant create view on mysqltest.* to mysqltest_1@localhost;
428 drop table v1;
429 use mysqltest;
430 create algorithm=TEMPTABLE view v1 as select *, a as b from t1;
431 create algorithm=MERGE view v2 as select *, a as b from t1;
432 create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select *, a as b from t1;
433 create algorithm=MERGE SQL SECURITY INVOKER view v4 as select *, a as b from t1;
434 create view v5 as select * from v1;
435 use test;
436 revoke select on t1 from mysqltest_1@localhost;
437 select * from v1;
438 ERROR HY000: View 'mysqltest.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
439 select * from v2;
440 ERROR HY000: View 'mysqltest.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
441 select * from v3;
442 a       b
443 1       1
444 select * from v4;
445 a       b
446 1       1
447 select * from v5;
448 ERROR HY000: View 'mysqltest.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
449 drop table t1;
450 use test;
451 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
452 drop database mysqltest;
453 create database mysqltest;
454 use mysqltest;
455 create table t1 (a int);
456 insert into t1 values (1);
457 create algorithm=TEMPTABLE view v1 as select *, a as b from t1;
458 create algorithm=MERGE view v2 as select *, a as b from t1;
459 create algorithm=TEMPTABLE SQL SECURITY INVOKER view v3 as select *, a as b from t1;
460 create algorithm=MERGE SQL SECURITY INVOKER view v4 as select *, a as b from t1;
461 create SQL SECURITY INVOKER view v5 as select * from v4;
462 grant select on v1 to mysqltest_1@localhost;
463 grant select on v2 to mysqltest_1@localhost;
464 grant select on v3 to mysqltest_1@localhost;
465 grant select on v4 to mysqltest_1@localhost;
466 grant select on v5 to mysqltest_1@localhost;
467 use mysqltest;
468 select * from v1;
469 a       b
470 1       1
471 select * from v2;
472 a       b
473 1       1
474 select * from v3;
475 ERROR HY000: View 'mysqltest.v3' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
476 select * from v4;
477 ERROR HY000: View 'mysqltest.v4' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
478 select * from v5;
479 ERROR HY000: View 'mysqltest.v5' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
480 use test;
481 drop view v1, v2, v3, v4, v5;
482 drop table t1;
483 use test;
484 REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_1@localhost;
485 drop database mysqltest;
486 drop view if exists v1;
487 drop table if exists t1;
488 create table t1 as select * from mysql.user where user='';
489 delete from mysql.user where user='';
490 flush privileges;
491 grant all on test.* to 'test14256'@'%';
492 use test;
493 create view v1 as select 42;
494 show create view v1;
495 View    Create View     character_set_client    collation_connection
496 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`test14256`@`%` SQL SECURITY DEFINER VIEW `v1` AS select 42 AS `42`  latin1  latin1_swedish_ci
497 select definer into @v1def1 from information_schema.views
498 where table_schema = 'test' and table_name='v1';
499 drop view v1;
500 create definer=`test14256`@`%` view v1 as select 42;
501 show create view v1;
502 View    Create View     character_set_client    collation_connection
503 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`test14256`@`%` SQL SECURITY DEFINER VIEW `v1` AS select 42 AS `42`  latin1  latin1_swedish_ci
504 select definer into @v1def2 from information_schema.views
505 where table_schema = 'test' and table_name='v1';
506 drop view v1;
507 select @v1def1, @v1def2, @v1def1=@v1def2;
508 @v1def1 @v1def2 @v1def1=@v1def2
509 test14256@%     test14256@%     1
510 drop user test14256;
511 insert into mysql.user select * from t1;
512 flush privileges;
513 drop table t1;
514 create database mysqltest;
515 use mysqltest;
516 CREATE TABLE t1 (i INT);
517 CREATE VIEW  v1 AS SELECT * FROM t1;
518 SHOW CREATE VIEW v1;
519 View    Create View     character_set_client    collation_connection
520 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1`        latin1  latin1_swedish_ci
521 GRANT SELECT, LOCK TABLES ON mysqltest.* TO mysqltest_1@localhost;
522 use mysqltest;
523 LOCK TABLES v1 READ;
524 SHOW CREATE TABLE v1;
525 ERROR 42000: SHOW VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v1'
526 UNLOCK TABLES;
527 use test;
528 use test;
529 drop user mysqltest_1@localhost;
530 drop database mysqltest;
531 create definer=some_user@`` sql security invoker view v1 as select 1;
532 Warnings:
533 Note    1449    The user specified as a definer ('some_user'@'') does not exist
534 create definer=some_user@localhost sql security invoker view v2 as select 1;
535 Warnings:
536 Note    1449    The user specified as a definer ('some_user'@'localhost') does not exist
537 show create view v1;
538 View    Create View     character_set_client    collation_connection
539 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1`     latin1  latin1_swedish_ci
540 show create view v2;
541 View    Create View     character_set_client    collation_connection
542 v2      CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select 1 AS `1`    latin1  latin1_swedish_ci
543 drop view v1;
544 drop view v2;
545 CREATE DATABASE mysqltest1;
546 CREATE USER readonly@localhost;
547 CREATE TABLE mysqltest1.t1 (x INT);
548 INSERT INTO mysqltest1.t1 VALUES (1), (2);
549 CREATE SQL SECURITY INVOKER VIEW mysqltest1.v_t1 AS SELECT * FROM mysqltest1.t1;
550 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ts AS SELECT * FROM mysqltest1.t1;
551 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_ti AS SELECT * FROM mysqltest1.t1;
552 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tu AS SELECT * FROM mysqltest1.t1;
553 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tus AS SELECT * FROM mysqltest1.t1;
554 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_td AS SELECT * FROM mysqltest1.t1;
555 CREATE SQL SECURITY DEFINER VIEW mysqltest1.v_tds AS SELECT * FROM mysqltest1.t1;
556 GRANT SELECT, INSERT, UPDATE, DELETE ON mysqltest1.v_t1 TO readonly@localhost;
557 GRANT SELECT ON mysqltest1.v_ts TO readonly@localhost;
558 GRANT INSERT ON mysqltest1.v_ti TO readonly@localhost;
559 GRANT UPDATE ON mysqltest1.v_tu TO readonly@localhost;
560 GRANT UPDATE,SELECT ON mysqltest1.v_tus TO readonly@localhost;
561 GRANT DELETE ON mysqltest1.v_td TO readonly@localhost;
562 GRANT DELETE,SELECT ON mysqltest1.v_tds TO readonly@localhost;
563 SELECT * FROM mysqltest1.v_t1;
564 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
565 INSERT INTO mysqltest1.v_t1 VALUES(4);
566 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
567 DELETE FROM mysqltest1.v_t1 WHERE x = 1;
568 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
569 UPDATE mysqltest1.v_t1 SET x = 3 WHERE x = 2;
570 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
571 UPDATE mysqltest1.v_t1 SET x = 3;
572 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
573 DELETE FROM mysqltest1.v_t1;
574 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
575 SELECT 1 FROM mysqltest1.v_t1;
576 ERROR HY000: View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
577 SELECT * FROM mysqltest1.t1;
578 ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 't1'
579 SELECT * FROM mysqltest1.v_ts;
583 SELECT * FROM mysqltest1.v_ts, mysqltest1.t1 WHERE mysqltest1.t1.x = mysqltest1.v_ts.x;
584 ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 't1'
585 SELECT * FROM mysqltest1.v_ti;
586 ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for table 'v_ti'
587 INSERT INTO mysqltest1.v_ts VALUES (100);
588 ERROR 42000: INSERT command denied to user 'readonly'@'localhost' for table 'v_ts'
589 INSERT INTO mysqltest1.v_ti VALUES (100);
590 UPDATE mysqltest1.v_ts SET x= 200 WHERE x = 100;
591 ERROR 42000: UPDATE command denied to user 'readonly'@'localhost' for table 'v_ts'
592 UPDATE mysqltest1.v_ts SET x= 200;
593 ERROR 42000: UPDATE command denied to user 'readonly'@'localhost' for table 'v_ts'
594 UPDATE mysqltest1.v_tu SET x= 200 WHERE x = 100;
595 UPDATE mysqltest1.v_tus SET x= 200 WHERE x = 100;
596 UPDATE mysqltest1.v_tu SET x= 200;
597 DELETE FROM mysqltest1.v_ts WHERE x= 200;
598 ERROR 42000: DELETE command denied to user 'readonly'@'localhost' for table 'v_ts'
599 DELETE FROM mysqltest1.v_ts;
600 ERROR 42000: DELETE command denied to user 'readonly'@'localhost' for table 'v_ts'
601 DELETE FROM mysqltest1.v_td WHERE x= 200;
602 ERROR 42000: SELECT command denied to user 'readonly'@'localhost' for column 'x' in table 'v_td'
603 DELETE FROM mysqltest1.v_tds WHERE x= 200;
604 DELETE FROM mysqltest1.v_td;
605 DROP VIEW mysqltest1.v_tds;
606 DROP VIEW mysqltest1.v_td;
607 DROP VIEW mysqltest1.v_tus;
608 DROP VIEW mysqltest1.v_tu;
609 DROP VIEW mysqltest1.v_ti;
610 DROP VIEW mysqltest1.v_ts;
611 DROP VIEW mysqltest1.v_t1;
612 DROP TABLE mysqltest1.t1;
613 DROP USER readonly@localhost;
614 DROP DATABASE mysqltest1;
615 CREATE TABLE t1 (a INT PRIMARY KEY);
616 INSERT INTO t1 VALUES (1), (2), (3);
617 CREATE DEFINER = 'no-such-user'@localhost VIEW v AS SELECT a from t1;
618 Warnings:
619 Note    1449    The user specified as a definer ('no-such-user'@'localhost') does not exist
620 SHOW CREATE VIEW v;
621 View    Create View     character_set_client    collation_connection
622 v       CREATE ALGORITHM=UNDEFINED DEFINER=`no-such-user`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `test`.`t1`.`a` AS `a` from `t1`  latin1  latin1_swedish_ci
623 Warnings:
624 Note    1449    The user specified as a definer ('no-such-user'@'localhost') does not exist
625 SELECT * FROM v;
626 ERROR HY000: The user specified as a definer ('no-such-user'@'localhost') does not exist
627 DROP VIEW v;
628 DROP TABLE t1;
629 USE test;
630 CREATE USER mysqltest_db1@localhost identified by 'PWD';
631 GRANT ALL ON mysqltest_db1.* TO mysqltest_db1@localhost WITH GRANT OPTION;
632 CREATE SCHEMA mysqltest_db1 ;
633 USE mysqltest_db1 ;
634 CREATE TABLE t1 (f1 INTEGER);
635 CREATE VIEW view1 AS
636 SELECT * FROM t1;
637 SHOW CREATE VIEW view1;
638 View    Create View     character_set_client    collation_connection
639 view1   CREATE ALGORITHM=UNDEFINED DEFINER=`mysqltest_db1`@`localhost` SQL SECURITY DEFINER VIEW `view1` AS select `t1`.`f1` AS `f1` from `t1`  latin1  latin1_swedish_ci
640 CREATE VIEW view2 AS
641 SELECT * FROM view1;
642 # Here comes a suspicious warning
643 SHOW CREATE VIEW view2;
644 View    Create View     character_set_client    collation_connection
645 view2   CREATE ALGORITHM=UNDEFINED DEFINER=`mysqltest_db1`@`localhost` SQL SECURITY DEFINER VIEW `view2` AS select `view1`.`f1` AS `f1` from `view1`    latin1  latin1_swedish_ci
646 # But the view view2 is usable
647 SELECT * FROM view2;
649 CREATE VIEW view3 AS
650 SELECT * FROM view2;
651 SELECT * from view3;
653 DROP VIEW mysqltest_db1.view3;
654 DROP VIEW mysqltest_db1.view2;
655 DROP VIEW mysqltest_db1.view1;
656 DROP TABLE mysqltest_db1.t1;
657 DROP SCHEMA mysqltest_db1;
658 DROP USER mysqltest_db1@localhost;
659 CREATE DATABASE test1;
660 CREATE DATABASE test2;
661 CREATE TABLE test1.t0 (a VARCHAR(20));
662 CREATE TABLE test2.t1 (a VARCHAR(20));
663 CREATE VIEW  test2.t3 AS SELECT * FROM test1.t0;
664 CREATE OR REPLACE VIEW test.v1 AS
665 SELECT ta.a AS col1, tb.a AS col2 FROM test2.t3 ta, test2.t1 tb;
666 DROP VIEW test.v1;
667 DROP VIEW test2.t3;
668 DROP TABLE test2.t1, test1.t0;
669 DROP DATABASE test2;
670 DROP DATABASE test1;
671 DROP VIEW IF EXISTS v1;
672 DROP VIEW IF EXISTS v2;
673 DROP VIEW IF EXISTS v3;
674 DROP FUNCTION IF EXISTS f1;
675 DROP FUNCTION IF EXISTS f2;
676 DROP PROCEDURE IF EXISTS p1;
677 CREATE SQL SECURITY DEFINER VIEW v1 AS SELECT CURRENT_USER() AS cu;
678 CREATE FUNCTION f1() RETURNS VARCHAR(77) SQL SECURITY INVOKER
679 RETURN CURRENT_USER();
680 CREATE SQL SECURITY DEFINER VIEW v2 AS SELECT f1() AS cu;
681 CREATE PROCEDURE p1(OUT cu VARCHAR(77)) SQL SECURITY INVOKER
682 SET cu= CURRENT_USER();
683 CREATE FUNCTION f2() RETURNS VARCHAR(77) SQL SECURITY INVOKER
684 BEGIN
685 DECLARE cu VARCHAR(77);
686 CALL p1(cu);
687 RETURN cu;
688 END|
689 CREATE SQL SECURITY DEFINER VIEW v3 AS SELECT f2() AS cu;
690 CREATE USER mysqltest_u1@localhost;
691 GRANT ALL ON test.* TO mysqltest_u1@localhost;
693 The following tests should all return 1.
695 SELECT CURRENT_USER() = 'mysqltest_u1@localhost';
696 CURRENT_USER() = 'mysqltest_u1@localhost'
698 SELECT f1() = 'mysqltest_u1@localhost';
699 f1() = 'mysqltest_u1@localhost'
701 CALL p1(@cu);
702 SELECT @cu = 'mysqltest_u1@localhost';
703 @cu = 'mysqltest_u1@localhost'
705 SELECT f2() = 'mysqltest_u1@localhost';
706 f2() = 'mysqltest_u1@localhost'
708 SELECT cu = 'root@localhost' FROM v1;
709 cu = 'root@localhost'
711 SELECT cu = 'root@localhost' FROM v2;
712 cu = 'root@localhost'
714 SELECT cu = 'root@localhost' FROM v3;
715 cu = 'root@localhost'
717 DROP VIEW v3;
718 DROP FUNCTION f2;
719 DROP PROCEDURE p1;
720 DROP FUNCTION f1;
721 DROP VIEW v2;
722 DROP VIEW v1;
723 DROP USER mysqltest_u1@localhost;
724 CREATE DATABASE db17254;
725 USE db17254;
726 CREATE TABLE t1 (f1 INT);
727 INSERT INTO t1 VALUES (10),(20);
728 CREATE USER def_17254@localhost;
729 GRANT SELECT ON db17254.* TO def_17254@localhost;
730 CREATE USER inv_17254@localhost;
731 GRANT SELECT ON db17254.t1 TO inv_17254@localhost;
732 GRANT CREATE VIEW ON db17254.* TO def_17254@localhost;
733 CREATE VIEW v1 AS SELECT * FROM t1;
734 DROP USER def_17254@localhost;
735 for a user
736 SELECT * FROM v1;
737 ERROR 42000: SELECT command denied to user 'inv_17254'@'localhost' for table 'v1'
738 for a superuser
739 SELECT * FROM v1;
740 ERROR HY000: The user specified as a definer ('def_17254'@'localhost') does not exist
741 DROP USER inv_17254@localhost;
742 DROP DATABASE db17254;
743 DROP DATABASE IF EXISTS mysqltest_db1;
744 DROP DATABASE IF EXISTS mysqltest_db2;
745 DROP USER mysqltest_u1;
746 DROP USER mysqltest_u2;
747 CREATE USER mysqltest_u1@localhost;
748 CREATE USER mysqltest_u2@localhost;
749 CREATE DATABASE mysqltest_db1;
750 CREATE DATABASE mysqltest_db2;
751 GRANT ALL ON mysqltest_db1.* TO mysqltest_u1@localhost WITH GRANT OPTION;
752 GRANT ALL ON mysqltest_db2.* TO mysqltest_u2@localhost;
753 CREATE TABLE t1 (i INT);
754 INSERT INTO t1 VALUES (1);
755 CREATE VIEW v1 AS SELECT i FROM t1 WHERE 1 IN (SELECT * FROM t1);
756 CREATE TABLE t2 (s CHAR(7));
757 INSERT INTO t2 VALUES ('public');
758 GRANT SELECT ON v1 TO mysqltest_u2@localhost;
759 GRANT SELECT ON t2 TO mysqltest_u2@localhost;
760 SELECT * FROM mysqltest_db1.v1, mysqltest_db1.t2;
761 i       s
762 1       public
763 PREPARE stmt1 FROM "SELECT * FROM mysqltest_db1.t2";
764 EXECUTE stmt1;
766 public
767 PREPARE stmt2 FROM "SELECT * FROM mysqltest_db1.v1, mysqltest_db1.t2";
768 EXECUTE stmt2;
769 i       s
770 1       public
771 REVOKE SELECT ON t2 FROM mysqltest_u2@localhost;
772 UPDATE t2 SET s = 'private' WHERE s = 'public';
773 SELECT * FROM mysqltest_db1.v1, mysqltest_db1.t2;
774 ERROR 42000: SELECT command denied to user 'mysqltest_u2'@'localhost' for table 't2'
775 EXECUTE stmt1;
776 ERROR 42000: SELECT command denied to user 'mysqltest_u2'@'localhost' for table 't2'
777 EXECUTE stmt2;
778 ERROR 42000: SELECT command denied to user 'mysqltest_u2'@'localhost' for table 't2'
779 REVOKE ALL ON mysqltest_db1.* FROM mysqltest_u1@localhost;
780 REVOKE ALL ON mysqltest_db2.* FROM mysqltest_u2@localhost;
781 DROP DATABASE mysqltest_db1;
782 DROP DATABASE mysqltest_db2;
783 DROP USER mysqltest_u1@localhost;
784 DROP USER mysqltest_u2@localhost;
785 CREATE DATABASE db26813;
786 USE db26813;
787 CREATE TABLE t1(f1 INT, f2 INT);
788 CREATE VIEW v1 AS SELECT f1 FROM t1;
789 CREATE VIEW v2 AS SELECT f1 FROM t1;
790 CREATE VIEW v3 AS SELECT f1 FROM t1;
791 CREATE USER u26813@localhost;
792 GRANT DROP ON db26813.v1 TO u26813@localhost;
793 GRANT CREATE VIEW ON db26813.v2 TO u26813@localhost;
794 GRANT DROP, CREATE VIEW ON db26813.v3 TO u26813@localhost;
795 GRANT SELECT ON db26813.t1 TO u26813@localhost;
796 ALTER VIEW v1 AS SELECT f2 FROM t1;
797 ERROR 42000: Access denied; you need the SUPER privilege for this operation
798 ALTER VIEW v2 AS SELECT f2 FROM t1;
799 ERROR 42000: Access denied; you need the SUPER privilege for this operation
800 ALTER VIEW v3 AS SELECT f2 FROM t1;
801 ERROR 42000: Access denied; you need the SUPER privilege for this operation
802 SHOW CREATE VIEW v3;
803 View    Create View     character_set_client    collation_connection
804 v3      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`f1` AS `f1` from `t1`      latin1  latin1_swedish_ci
805 DROP USER u26813@localhost;
806 DROP DATABASE db26813;
808 # Bug#29908 A user can gain additional access through the ALTER VIEW.
810 CREATE DATABASE mysqltest_29908;
811 USE mysqltest_29908;
812 CREATE TABLE t1(f1 INT, f2 INT);
813 CREATE USER u29908_1@localhost;
814 CREATE DEFINER = u29908_1@localhost VIEW v1 AS SELECT f1 FROM t1;
815 CREATE DEFINER = u29908_1@localhost SQL SECURITY INVOKER VIEW v2 AS
816 SELECT f1 FROM t1;
817 GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v1 TO u29908_1@localhost;
818 GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_1@localhost;
819 GRANT SELECT ON mysqltest_29908.t1 TO u29908_1@localhost;
820 CREATE USER u29908_2@localhost;
821 GRANT DROP, CREATE VIEW ON mysqltest_29908.v1 TO u29908_2@localhost;
822 GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_2@localhost;
823 GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost;
824 ALTER VIEW v1 AS SELECT f2 FROM t1;
825 ERROR 42000: Access denied; you need the SUPER privilege for this operation
826 ALTER VIEW v2 AS SELECT f2 FROM t1;
827 ERROR 42000: Access denied; you need the SUPER privilege for this operation
828 SHOW CREATE VIEW v2;
829 View    Create View     character_set_client    collation_connection
830 v2      CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1`  latin1  latin1_swedish_ci
831 ALTER VIEW v1 AS SELECT f2 FROM t1;
832 SHOW CREATE VIEW v1;
833 View    Create View     character_set_client    collation_connection
834 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f2` AS `f2` from `t1`  latin1  latin1_swedish_ci
835 ALTER VIEW v2 AS SELECT f2 FROM t1;
836 SHOW CREATE VIEW v2;
837 View    Create View     character_set_client    collation_connection
838 v2      CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f2` AS `f2` from `t1`  latin1  latin1_swedish_ci
839 ALTER VIEW v1 AS SELECT f1 FROM t1;
840 SHOW CREATE VIEW v1;
841 View    Create View     character_set_client    collation_connection
842 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`f1` AS `f1` from `t1`  latin1  latin1_swedish_ci
843 ALTER VIEW v2 AS SELECT f1 FROM t1;
844 SHOW CREATE VIEW v2;
845 View    Create View     character_set_client    collation_connection
846 v2      CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1`  latin1  latin1_swedish_ci
847 DROP USER u29908_1@localhost;
848 DROP USER u29908_2@localhost;
849 DROP DATABASE mysqltest_29908;
850 #######################################################################
851 DROP DATABASE IF EXISTS mysqltest1;
852 DROP DATABASE IF EXISTS mysqltest2;
853 CREATE DATABASE mysqltest1;
854 CREATE DATABASE mysqltest2;
855 CREATE TABLE mysqltest1.t1(c1 INT);
856 CREATE TABLE mysqltest1.t2(c2 INT);
857 CREATE TABLE mysqltest1.t3(c3 INT);
858 CREATE TABLE mysqltest1.t4(c4 INT);
859 INSERT INTO mysqltest1.t1 VALUES (11), (12), (13), (14);
860 INSERT INTO mysqltest1.t2 VALUES (21), (22), (23), (24);
861 INSERT INTO mysqltest1.t3 VALUES (31), (32), (33), (34);
862 INSERT INTO mysqltest1.t4 VALUES (41), (42), (43), (44);
863 GRANT SELECT ON mysqltest1.t1 TO mysqltest_u1@localhost;
864 GRANT INSERT ON mysqltest1.t2 TO mysqltest_u1@localhost;
865 GRANT SELECT, UPDATE ON mysqltest1.t3 TO mysqltest_u1@localhost;
866 GRANT SELECT, DELETE ON mysqltest1.t4 TO mysqltest_u1@localhost;
867 GRANT ALL PRIVILEGES ON mysqltest2.* TO mysqltest_u1@localhost;
869 ---> connection: bug24040_con
870 SELECT * FROM mysqltest1.t1;
876 INSERT INTO mysqltest1.t2 VALUES(25);
877 UPDATE mysqltest1.t3 SET c3 = 331 WHERE c3 = 31;
878 DELETE FROM mysqltest1.t4 WHERE c4 = 44;
879 CREATE VIEW v1 AS SELECT * FROM mysqltest1.t1;
880 CREATE VIEW v2 AS SELECT * FROM mysqltest1.t2;
881 CREATE VIEW v3 AS SELECT * FROM mysqltest1.t3;
882 CREATE VIEW v4 AS SELECT * FROM mysqltest1.t4;
883 SELECT * FROM v1;
889 INSERT INTO v2 VALUES(26);
890 UPDATE v3 SET c3 = 332 WHERE c3 = 32;
891 DELETE FROM v4 WHERE c4 = 43;
892 CREATE VIEW v12 AS SELECT c1, c2 FROM mysqltest1.t1, mysqltest1.t2;
893 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c2' in table 'v12'
894 CREATE VIEW v13 AS SELECT c1, c3 FROM mysqltest1.t1, mysqltest1.t3;
895 CREATE VIEW v14 AS SELECT c1, c4 FROM mysqltest1.t1, mysqltest1.t4;
896 CREATE VIEW v21 AS SELECT c2, c1 FROM mysqltest1.t2, mysqltest1.t1;
897 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c1' in table 'v21'
898 CREATE VIEW v23 AS SELECT c2, c3 FROM mysqltest1.t2, mysqltest1.t3;
899 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c3' in table 'v23'
900 CREATE VIEW v24 AS SELECT c2, c4 FROM mysqltest1.t2, mysqltest1.t4;
901 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c4' in table 'v24'
902 CREATE VIEW v31 AS SELECT c3, c1 FROM mysqltest1.t3, mysqltest1.t1;
903 CREATE VIEW v32 AS SELECT c3, c2 FROM mysqltest1.t3, mysqltest1.t2;
904 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c2' in table 'v32'
905 CREATE VIEW v34 AS SELECT c3, c4 FROM mysqltest1.t3, mysqltest1.t4;
906 CREATE VIEW v41 AS SELECT c4, c1 FROM mysqltest1.t4, mysqltest1.t1;
907 CREATE VIEW v42 AS SELECT c4, c2 FROM mysqltest1.t4, mysqltest1.t2;
908 ERROR 42000: create view command denied to user 'mysqltest_u1'@'localhost' for column 'c2' in table 'v42'
909 CREATE VIEW v43 AS SELECT c4, c3 FROM mysqltest1.t4, mysqltest1.t3;
911 ---> connection: default
912 SELECT * FROM mysqltest1.t1;
918 SELECT * FROM mysqltest1.t2;
926 SELECT * FROM mysqltest1.t3;
932 SELECT * FROM mysqltest1.t4;
936 DROP DATABASE mysqltest1;
937 DROP DATABASE mysqltest2;
938 DROP USER mysqltest_u1@localhost;
939 CREATE DATABASE db1;
940 USE db1;
941 CREATE TABLE t1(f1 INT, f2 INT);
942 CREATE VIEW v1 AS SELECT f1, f2 FROM t1;
943 GRANT SELECT (f1) ON t1 TO foo;
944 GRANT SELECT (f1) ON v1 TO foo;
945 USE db1;
946 SELECT f1 FROM t1;
948 SELECT f2 FROM t1;
949 ERROR 42000: SELECT command denied to user 'foo'@'localhost' for column 'f2' in table 't1'
950 SELECT * FROM t1;
951 ERROR 42000: SELECT command denied to user 'foo'@'localhost' for table 't1'
952 SELECT f1 FROM v1;
954 SELECT f2 FROM v1;
955 ERROR 42000: SELECT command denied to user 'foo'@'localhost' for column 'f2' in table 'v1'
956 SELECT * FROM v1;
957 ERROR 42000: SELECT command denied to user 'foo'@'localhost' for table 'v1'
958 USE test;
959 REVOKE SELECT (f1) ON db1.t1 FROM foo;
960 REVOKE SELECT (f1) ON db1.v1 FROM foo;
961 DROP USER foo;
962 DROP VIEW db1.v1;
963 DROP TABLE db1.t1;
964 DROP DATABASE db1;
965 Bug #11765687/#58677: 
966 No privilege on table/view, but can know #rows / underlying table's name
967 create database mysqltest1;
968 create table mysqltest1.t1 (i int);
969 create table mysqltest1.t2 (j int);
970 create table mysqltest1.t3 (k int, secret int);
971 create user alice@localhost;
972 create user bob@localhost;
973 create user cecil@localhost;
974 create user dan@localhost;
975 create user eugene@localhost;
976 create user fiona@localhost;
977 create user greg@localhost;
978 create user han@localhost;
979 create user inga@localhost;
980 create user jamie@localhost;
981 create user karl@localhost;
982 create user lena@localhost;
983 create user mhairi@localhost;
984 create user noam@localhost;
985 create user olga@localhost;
986 create user pjotr@localhost;
987 create user quintessa@localhost;
988 grant all privileges on mysqltest1.* to alice@localhost with grant option;
989 ... as alice
990 create view v1 as select * from t1;
991 create view v2 as select * from v1, t2;
992 create view v3 as select k from t3;
993 grant select            on mysqltest1.v1 to bob@localhost;
994 grant show view         on mysqltest1.v1 to cecil@localhost;
995 grant select, show view on mysqltest1.v1 to dan@localhost;
996 grant select            on mysqltest1.t1 to dan@localhost;
997 grant select            on mysqltest1.*  to eugene@localhost;
998 grant select, show view on mysqltest1.v2 to fiona@localhost;
999 grant select, show view on mysqltest1.v2 to greg@localhost;
1000 grant         show view on mysqltest1.v1 to greg@localhost;
1001 grant select(k)         on mysqltest1.t3 to han@localhost;
1002 grant select, show view on mysqltest1.v3 to han@localhost;
1003 grant select            on mysqltest1.t1 to inga@localhost;
1004 grant select            on mysqltest1.t2 to inga@localhost;
1005 grant select            on mysqltest1.v1 to inga@localhost;
1006 grant select, show view on mysqltest1.v2 to inga@localhost;
1007 grant select            on mysqltest1.t1 to jamie@localhost;
1008 grant select            on mysqltest1.t2 to jamie@localhost;
1009 grant         show view on mysqltest1.v1 to jamie@localhost;
1010 grant select, show view on mysqltest1.v2 to jamie@localhost;
1011 grant select            on mysqltest1.t1 to karl@localhost;
1012 grant select            on mysqltest1.t2 to karl@localhost;
1013 grant select, show view on mysqltest1.v1 to karl@localhost;
1014 grant select            on mysqltest1.v2 to karl@localhost;
1015 grant select            on mysqltest1.t1 to lena@localhost;
1016 grant select            on mysqltest1.t2 to lena@localhost;
1017 grant select, show view on mysqltest1.v1 to lena@localhost;
1018 grant         show view on mysqltest1.v2 to lena@localhost;
1019 grant select            on mysqltest1.t1 to mhairi@localhost;
1020 grant select            on mysqltest1.t2 to mhairi@localhost;
1021 grant select, show view on mysqltest1.v1 to mhairi@localhost;
1022 grant select, show view on mysqltest1.v2 to mhairi@localhost;
1023 grant select            on mysqltest1.t1 to noam@localhost;
1024 grant select, show view on mysqltest1.v1 to noam@localhost;
1025 grant select, show view on mysqltest1.v2 to noam@localhost;
1026 grant select            on mysqltest1.t2 to olga@localhost;
1027 grant select, show view on mysqltest1.v1 to olga@localhost;
1028 grant select, show view on mysqltest1.v2 to olga@localhost;
1029 grant select            on mysqltest1.t1 to pjotr@localhost;
1030 grant select            on mysqltest1.t2 to pjotr@localhost;
1031 grant select, show view on mysqltest1.v2 to pjotr@localhost;
1032 grant select, show view on mysqltest1.v1 to quintessa@localhost;
1033 ... as bob
1034 select * from v1;
1036 explain select * from v1;
1037 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1038 ... as cecil
1039 select * from v1;
1040 ERROR 42000: SELECT command denied to user 'cecil'@'localhost' for table 'v1'
1041 explain select * from v1;
1042 ERROR 42000: SELECT command denied to user 'cecil'@'localhost' for table 'v1'
1043 ... as dan
1044 select * from v1;
1046 explain select * from v1;
1047 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1048 1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    0       const row not found
1049 ... as eugene
1050 select * from v1;
1052 explain select * from v1;
1053 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1054 ... as fiona
1055 select * from v2;
1056 i       j
1057 show create view v2;
1058 View    Create View     character_set_client    collation_connection
1059 v2      CREATE ALGORITHM=UNDEFINED DEFINER=`alice`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `v1`.`i` AS `i`,`t2`.`j` AS `j` from (`v1` join `t2`)   latin1  latin1_swedish_ci
1060 explain select * from t1;
1061 ERROR 42000: SELECT command denied to user 'fiona'@'localhost' for table 't1'
1062 explain select * from v1;
1063 ERROR 42000: SELECT command denied to user 'fiona'@'localhost' for table 'v1'
1064 explain select * from t2;
1065 ERROR 42000: SELECT command denied to user 'fiona'@'localhost' for table 't2'
1066 explain select * from v2;
1067 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1068 ... as greg
1069 select * from v2;
1070 i       j
1071 explain select * from v1;
1072 ERROR 42000: SELECT command denied to user 'greg'@'localhost' for table 'v1'
1073 explain select * from v2;
1074 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1075 ... as han
1076 select * from t3;
1077 ERROR 42000: SELECT command denied to user 'han'@'localhost' for table 't3'
1078 explain select * from t3;
1079 ERROR 42000: SELECT command denied to user 'han'@'localhost' for table 't3'
1080 select k from t3;
1082 explain select k from t3;
1083 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1084 1       SIMPLE  t3      system  NULL    NULL    NULL    NULL    0       const row not found
1085 select * from v3;
1087 explain select * from v3;
1088 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1089 1       SIMPLE  t3      system  NULL    NULL    NULL    NULL    0       const row not found
1090 ... as inga
1091 select * from v2;
1092 i       j
1093 explain select * from v2;
1094 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1095 ... as jamie
1096 select * from v2;
1097 i       j
1098 explain select * from v2;
1099 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1100 ... as karl
1101 select * from v2;
1102 i       j
1103 explain select * from v2;
1104 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1105 ... as lena
1106 select * from v2;
1107 ERROR 42000: SELECT command denied to user 'lena'@'localhost' for table 'v2'
1108 explain select * from v2;
1109 ERROR 42000: SELECT command denied to user 'lena'@'localhost' for table 'v2'
1110 ... as mhairi
1111 select * from v2;
1112 i       j
1113 explain select * from v2;
1114 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1115 1       SIMPLE  t1      system  NULL    NULL    NULL    NULL    0       const row not found
1116 1       SIMPLE  t2      system  NULL    NULL    NULL    NULL    0       const row not found
1117 ... as noam
1118 select * from v2;
1119 i       j
1120 explain select * from v2;
1121 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1122 ... as olga
1123 select * from v2;
1124 i       j
1125 explain select * from v2;
1126 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1127 ... as pjotr
1128 select * from v2;
1129 i       j
1130 explain select * from v2;
1131 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1132 ... as quintessa
1133 select * from v1;
1135 explain select * from v1;
1136 ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
1137 ... as root again at last: clean-up time!
1138 drop user alice@localhost;
1139 drop user bob@localhost;
1140 drop user cecil@localhost;
1141 drop user dan@localhost;
1142 drop user eugene@localhost;
1143 drop user fiona@localhost;
1144 drop user greg@localhost;
1145 drop user han@localhost;
1146 drop user inga@localhost;
1147 drop user jamie@localhost;
1148 drop user karl@localhost;
1149 drop user lena@localhost;
1150 drop user mhairi@localhost;
1151 drop user noam@localhost;
1152 drop user olga@localhost;
1153 drop user pjotr@localhost;
1154 drop user quintessa@localhost;
1155 drop database mysqltest1;
1156 End of 5.0 tests.
1157 DROP VIEW IF EXISTS v1;
1158 DROP TABLE IF EXISTS t1;
1159 CREATE TABLE t1 (i INT);
1160 CREATE VIEW v1 AS SELECT * FROM t1;
1161 ALTER VIEW v1 AS SELECT * FROM t1;
1162 SHOW CREATE VIEW v1;
1163 View    Create View     character_set_client    collation_connection
1164 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1`        latin1  latin1_swedish_ci
1165 ALTER DEFINER=no_such@user_1 VIEW v1 AS SELECT * FROM t1;
1166 Warnings:
1167 Note    1449    The user specified as a definer ('no_such'@'user_1') does not exist
1168 SHOW CREATE VIEW v1;
1169 View    Create View     character_set_client    collation_connection
1170 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`no_such`@`user_1` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`i` AS `i` from `t1` latin1  latin1_swedish_ci
1171 Warnings:
1172 Note    1449    The user specified as a definer ('no_such'@'user_1') does not exist
1173 ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
1174 Warnings:
1175 Note    1449    The user specified as a definer ('no_such'@'user_1') does not exist
1176 SHOW CREATE VIEW v1;
1177 View    Create View     character_set_client    collation_connection
1178 v1      CREATE ALGORITHM=MERGE DEFINER=`no_such`@`user_1` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`i` AS `i` from `t1`     latin1  latin1_swedish_ci
1179 Warnings:
1180 Note    1449    The user specified as a definer ('no_such'@'user_1') does not exist
1181 ALTER ALGORITHM=TEMPTABLE DEFINER=no_such@user_2 VIEW v1 AS SELECT * FROM t1;
1182 Warnings:
1183 Note    1449    The user specified as a definer ('no_such'@'user_2') does not exist
1184 SHOW CREATE VIEW v1;
1185 View    Create View     character_set_client    collation_connection
1186 v1      CREATE ALGORITHM=TEMPTABLE DEFINER=`no_such`@`user_2` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`i` AS `i` from `t1` latin1  latin1_swedish_ci
1187 Warnings:
1188 Note    1449    The user specified as a definer ('no_such'@'user_2') does not exist
1189 DROP VIEW v1;
1190 DROP TABLE t1;
1191 CREATE USER mysqluser1@localhost;
1192 CREATE DATABASE mysqltest1;
1193 USE mysqltest1;
1194 CREATE TABLE t1 ( a INT );
1195 CREATE TABLE t2 ( b INT );
1196 INSERT INTO t1 VALUES (1), (2);
1197 INSERT INTO t2 VALUES (1), (2);
1198 GRANT CREATE VIEW ON mysqltest1.* TO mysqluser1@localhost;
1199 GRANT SELECT ON t1 TO mysqluser1@localhost;
1200 GRANT INSERT ON t2 TO mysqluser1@localhost;
1201 This would lead to failed assertion.
1202 CREATE VIEW v1 AS SELECT a, b FROM t1, t2;
1203 SELECT * FROM v1;
1204 ERROR 42000: SELECT command denied to user 'mysqluser1'@'localhost' for table 'v1'
1205 SELECT b FROM v1;
1206 ERROR 42000: SELECT command denied to user 'mysqluser1'@'localhost' for table 'v1'
1207 DROP TABLE t1, t2;
1208 DROP VIEW v1;
1209 DROP DATABASE mysqltest1;
1210 DROP USER mysqluser1@localhost;
1211 USE test;
1212 End of 5.1 tests.
1213 CREATE USER mysqluser1@localhost;
1214 CREATE DATABASE mysqltest1;
1215 USE mysqltest1;
1216 CREATE TABLE t1 ( a INT, b INT );
1217 CREATE TABLE t2 ( a INT, b INT );
1218 CREATE VIEW v1 AS SELECT a, b FROM t1;
1219 GRANT SELECT( a ) ON v1 TO mysqluser1@localhost;
1220 GRANT UPDATE( b ) ON t2 TO mysqluser1@localhost;
1221 SELECT * FROM mysqltest1.v1;
1222 ERROR 42000: SELECT command denied to user 'mysqluser1'@'localhost' for table 'v1'
1223 CREATE VIEW v1 AS SELECT * FROM mysqltest1.t2;
1224 ERROR 42000: ANY command denied to user 'mysqluser1'@'localhost' for table 't2'
1225 DROP TABLE t1, t2;
1226 DROP VIEW v1;
1227 DROP DATABASE mysqltest1;
1228 DROP USER mysqluser1@localhost;
1229 CREATE USER mysqluser1@localhost;
1230 CREATE DATABASE mysqltest1;
1231 USE mysqltest1;
1232 CREATE VIEW v1 AS SELECT * FROM information_schema.tables LIMIT 1;
1233 CREATE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT 1 AS A;
1234 CREATE VIEW test.v3 AS SELECT 1 AS a;
1235 GRANT SELECT ON mysqltest1.* to mysqluser1@localhost;
1236 GRANT ALL ON test.* TO mysqluser1@localhost;
1237 PREPARE stmt_v1     FROM "SELECT * FROM mysqltest1.v1";
1238 PREPARE stmt_v2 FROM "SELECT * FROM mysqltest1.v2";
1239 REVOKE SELECT ON mysqltest1.* FROM mysqluser1@localhost;
1240 EXECUTE stmt_v1;
1241 ERROR 42000: SELECT command denied to user 'mysqluser1'@'localhost' for table 'v1'
1242 EXECUTE stmt_v2;
1243 ERROR 42000: SELECT command denied to user 'mysqluser1'@'localhost' for table 'v2'
1244 PREPARE stmt FROM "SELECT a FROM v3";
1245 EXECUTE stmt;
1248 DROP VIEW v1, v2;
1249 DROP DATABASE mysqltest1;
1250 DROP VIEW test.v3;
1251 DROP USER mysqluser1@localhost;
1252 USE test;
1254 # Bug#35996: SELECT + SHOW VIEW should be enough to display view 
1255 # definition
1257 CREATE USER mysqluser1@localhost;
1258 CREATE DATABASE mysqltest1;
1259 CREATE DATABASE mysqltest2;
1260 GRANT USAGE, SELECT, CREATE VIEW, SHOW VIEW 
1261 ON mysqltest2.* TO mysqluser1@localhost;
1262 USE mysqltest1;
1263 CREATE TABLE t1( a INT );
1264 CREATE TABLE t2( a INT, b INT );
1265 CREATE FUNCTION f1() RETURNS INT RETURN 1;
1266 CREATE VIEW v1 AS SELECT 1 AS a;
1267 CREATE VIEW v2 AS SELECT 1 AS a, 2 AS b;
1268 GRANT SELECT        ON TABLE    t1 TO mysqluser1@localhost;
1269 GRANT SELECT (a, b) ON TABLE    t2 TO mysqluser1@localhost;
1270 GRANT EXECUTE       ON FUNCTION f1 TO mysqluser1@localhost;
1271 GRANT SELECT        ON TABLE    v1 TO mysqluser1@localhost;
1272 GRANT SELECT (a, b) ON TABLE    v2 TO mysqluser1@localhost;
1273 CREATE VIEW v_t1 AS SELECT * FROM t1;
1274 CREATE VIEW v_t2 AS SELECT * FROM t2;
1275 CREATE VIEW v_f1 AS SELECT f1() AS a;
1276 CREATE VIEW v_v1 AS SELECT * FROM v1;
1277 CREATE VIEW v_v2 AS SELECT * FROM v2;
1278 GRANT SELECT, SHOW VIEW ON v_t1 TO mysqluser1@localhost;
1279 GRANT SELECT, SHOW VIEW ON v_t2 TO mysqluser1@localhost;
1280 GRANT SELECT, SHOW VIEW ON v_f1 TO mysqluser1@localhost;
1281 GRANT SELECT, SHOW VIEW ON v_v1 TO mysqluser1@localhost;
1282 GRANT SELECT, SHOW VIEW ON v_v2 TO mysqluser1@localhost;
1283 CREATE VIEW v_mysqluser1_t1 AS SELECT * FROM mysqltest1.t1;
1284 CREATE VIEW v_mysqluser1_t2 AS SELECT * FROM mysqltest1.t2;
1285 CREATE VIEW v_mysqluser1_f1 AS SELECT mysqltest1.f1() AS a;
1286 CREATE VIEW v_mysqluser1_v1 AS SELECT * FROM mysqltest1.v1;
1287 CREATE VIEW v_mysqluser1_v2 AS SELECT * FROM mysqltest1.v2;
1288 SHOW CREATE VIEW mysqltest1.v_t1;
1289 View    Create View     character_set_client    collation_connection
1290 v_t1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`       latin1  latin1_swedish_ci
1291 SHOW CREATE VIEW mysqltest1.v_t2;
1292 View    Create View     character_set_client    collation_connection
1293 v_t2    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_t2` AS select `mysqltest1`.`t2`.`a` AS `a`,`mysqltest1`.`t2`.`b` AS `b` from `mysqltest1`.`t2`  latin1  latin1_swedish_ci
1294 SHOW CREATE VIEW mysqltest1.v_f1;
1295 View    Create View     character_set_client    collation_connection
1296 v_f1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_f1` AS select `f1`() AS `a`     latin1  latin1_swedish_ci
1297 SHOW CREATE VIEW mysqltest1.v_v1;
1298 View    Create View     character_set_client    collation_connection
1299 v_v1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`    latin1  latin1_swedish_ci
1300 SHOW CREATE VIEW mysqltest1.v_v2;
1301 View    Create View     character_set_client    collation_connection
1302 v_v2    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_v2` AS select `v2`.`a` AS `a`,`v2`.`b` AS `b` from `mysqltest1`.`v2`    latin1  latin1_swedish_ci
1303 SHOW CREATE VIEW v_mysqluser1_t1;
1304 View    Create View     character_set_client    collation_connection
1305 v_mysqluser1_t1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`   latin1  latin1_swedish_ci
1306 SHOW CREATE VIEW v_mysqluser1_t2;
1307 View    Create View     character_set_client    collation_connection
1308 v_mysqluser1_t2 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t2` AS select `mysqltest1`.`t2`.`a` AS `a`,`mysqltest1`.`t2`.`b` AS `b` from `mysqltest1`.`t2`      latin1  latin1_swedish_ci
1309 SHOW CREATE VIEW v_mysqluser1_f1;
1310 View    Create View     character_set_client    collation_connection
1311 v_mysqluser1_f1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_f1` AS select `mysqltest1`.`f1`() AS `a`    latin1  latin1_swedish_ci
1312 SHOW CREATE VIEW v_mysqluser1_v1;
1313 View    Create View     character_set_client    collation_connection
1314 v_mysqluser1_v1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`        latin1  latin1_swedish_ci
1315 SHOW CREATE VIEW v_mysqluser1_v2;
1316 View    Create View     character_set_client    collation_connection
1317 v_mysqluser1_v2 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v2` AS select `v2`.`a` AS `a`,`v2`.`b` AS `b` from `mysqltest1`.`v2`        latin1  latin1_swedish_ci
1318 REVOKE SELECT     ON TABLE    t1 FROM mysqluser1@localhost;
1319 REVOKE SELECT (a) ON TABLE    t2 FROM mysqluser1@localhost;
1320 REVOKE EXECUTE    ON FUNCTION f1 FROM mysqluser1@localhost;
1321 REVOKE SELECT     ON TABLE    v1 FROM mysqluser1@localhost;
1322 SHOW CREATE VIEW mysqltest1.v_t1;
1323 View    Create View     character_set_client    collation_connection
1324 v_t1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`       latin1  latin1_swedish_ci
1325 SHOW CREATE VIEW mysqltest1.v_t2;
1326 View    Create View     character_set_client    collation_connection
1327 v_t2    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_t2` AS select `mysqltest1`.`t2`.`a` AS `a`,`mysqltest1`.`t2`.`b` AS `b` from `mysqltest1`.`t2`  latin1  latin1_swedish_ci
1328 SHOW CREATE VIEW mysqltest1.v_f1;
1329 View    Create View     character_set_client    collation_connection
1330 v_f1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_f1` AS select `f1`() AS `a`     latin1  latin1_swedish_ci
1331 SHOW CREATE VIEW mysqltest1.v_v1;
1332 View    Create View     character_set_client    collation_connection
1333 v_v1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`    latin1  latin1_swedish_ci
1334 SHOW CREATE VIEW mysqltest1.v_v2;
1335 View    Create View     character_set_client    collation_connection
1336 v_v2    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_v2` AS select `v2`.`a` AS `a`,`v2`.`b` AS `b` from `mysqltest1`.`v2`    latin1  latin1_swedish_ci
1337 SHOW CREATE VIEW v_mysqluser1_t1;
1338 View    Create View     character_set_client    collation_connection
1339 v_mysqluser1_t1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`   latin1  latin1_swedish_ci
1340 SHOW CREATE VIEW v_mysqluser1_t2;
1341 View    Create View     character_set_client    collation_connection
1342 v_mysqluser1_t2 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t2` AS select `mysqltest1`.`t2`.`a` AS `a`,`mysqltest1`.`t2`.`b` AS `b` from `mysqltest1`.`t2`      latin1  latin1_swedish_ci
1343 SHOW CREATE VIEW v_mysqluser1_f1;
1344 View    Create View     character_set_client    collation_connection
1345 v_mysqluser1_f1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_f1` AS select `mysqltest1`.`f1`() AS `a`    latin1  latin1_swedish_ci
1346 SHOW CREATE VIEW v_mysqluser1_v1;
1347 View    Create View     character_set_client    collation_connection
1348 v_mysqluser1_v1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`        latin1  latin1_swedish_ci
1349 SHOW CREATE VIEW v_mysqluser1_v2;
1350 View    Create View     character_set_client    collation_connection
1351 v_mysqluser1_v2 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v2` AS select `v2`.`a` AS `a`,`v2`.`b` AS `b` from `mysqltest1`.`v2`        latin1  latin1_swedish_ci
1352 # Testing the case when the views reference missing objects.
1353 # Obviously, there are no privileges to check for, so we
1354 # need only each object type once.
1355 DROP TABLE t1;
1356 DROP FUNCTION f1;
1357 DROP VIEW v1;
1358 SHOW CREATE VIEW mysqltest1.v_t1;
1359 View    Create View     character_set_client    collation_connection
1360 v_t1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`       latin1  latin1_swedish_ci
1361 Warnings:
1362 Warning 1356    View 'mysqltest1.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1363 SHOW CREATE VIEW mysqltest1.v_f1;
1364 View    Create View     character_set_client    collation_connection
1365 v_f1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_f1` AS select `f1`() AS `a`     latin1  latin1_swedish_ci
1366 Warnings:
1367 Warning 1356    View 'mysqltest1.v_f1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1368 SHOW CREATE VIEW mysqltest1.v_v1;
1369 View    Create View     character_set_client    collation_connection
1370 v_v1    CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `mysqltest1`.`v_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`    latin1  latin1_swedish_ci
1371 Warnings:
1372 Warning 1356    View 'mysqltest1.v_v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1373 SHOW CREATE VIEW v_mysqluser1_t1;
1374 View    Create View     character_set_client    collation_connection
1375 v_mysqluser1_t1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`   latin1  latin1_swedish_ci
1376 Warnings:
1377 Warning 1356    View 'mysqltest2.v_mysqluser1_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1378 SHOW CREATE VIEW v_mysqluser1_f1;
1379 View    Create View     character_set_client    collation_connection
1380 v_mysqluser1_f1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_f1` AS select `mysqltest1`.`f1`() AS `a`    latin1  latin1_swedish_ci
1381 Warnings:
1382 Warning 1356    View 'mysqltest2.v_mysqluser1_f1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1383 SHOW CREATE VIEW v_mysqluser1_v1;
1384 View    Create View     character_set_client    collation_connection
1385 v_mysqluser1_v1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`        latin1  latin1_swedish_ci
1386 Warnings:
1387 Warning 1356    View 'mysqltest2.v_mysqluser1_v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1388 REVOKE SHOW VIEW ON v_t1 FROM mysqluser1@localhost;
1389 REVOKE SHOW VIEW ON v_f1 FROM mysqluser1@localhost;
1390 REVOKE SHOW VIEW ON v_v1 FROM mysqluser1@localhost;
1391 SHOW CREATE VIEW mysqltest1.v_t1;
1392 ERROR 42000: SHOW VIEW command denied to user 'mysqluser1'@'localhost' for table 'v_t1'
1393 SHOW CREATE VIEW mysqltest1.v_f1;
1394 ERROR 42000: SHOW VIEW command denied to user 'mysqluser1'@'localhost' for table 'v_f1'
1395 SHOW CREATE VIEW mysqltest1.v_v1;
1396 ERROR 42000: SHOW VIEW command denied to user 'mysqluser1'@'localhost' for table 'v_v1'
1397 SHOW CREATE VIEW v_mysqluser1_t1;
1398 View    Create View     character_set_client    collation_connection
1399 v_mysqluser1_t1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_t1` AS select `mysqltest1`.`t1`.`a` AS `a` from `mysqltest1`.`t1`   latin1  latin1_swedish_ci
1400 Warnings:
1401 Warning 1356    View 'mysqltest2.v_mysqluser1_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1402 SHOW CREATE VIEW v_mysqluser1_f1;
1403 View    Create View     character_set_client    collation_connection
1404 v_mysqluser1_f1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_f1` AS select `mysqltest1`.`f1`() AS `a`    latin1  latin1_swedish_ci
1405 Warnings:
1406 Warning 1356    View 'mysqltest2.v_mysqluser1_f1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1407 SHOW CREATE VIEW v_mysqluser1_v1;
1408 View    Create View     character_set_client    collation_connection
1409 v_mysqluser1_v1 CREATE ALGORITHM=UNDEFINED DEFINER=`mysqluser1`@`localhost` SQL SECURITY DEFINER VIEW `v_mysqluser1_v1` AS select `v1`.`a` AS `a` from `mysqltest1`.`v1`        latin1  latin1_swedish_ci
1410 Warnings:
1411 Warning 1356    View 'mysqltest2.v_mysqluser1_v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1412 DROP USER mysqluser1@localhost;
1413 DROP DATABASE mysqltest1;
1414 DROP DATABASE mysqltest2;
1415 USE test;
1416 CREATE TABLE t1( a INT );
1417 CREATE DEFINER = no_such_user@no_such_host VIEW v1 AS SELECT * FROM t1;
1418 Warnings:
1419 Note    1449    The user specified as a definer ('no_such_user'@'no_such_host') does not exist
1420 SHOW CREATE VIEW v1;
1421 View    Create View     character_set_client    collation_connection
1422 v1      CREATE ALGORITHM=UNDEFINED DEFINER=`no_such_user`@`no_such_host` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t1`.`a` AS `a` from `t1`      latin1  latin1_swedish_ci
1423 Warnings:
1424 Note    1449    The user specified as a definer ('no_such_user'@'no_such_host') does not exist
1425 DROP TABLE t1;
1426 DROP VIEW v1;
1428 # Bug #46019: ERROR 1356 When selecting from within another 
1429 #  view that has Group By
1431 CREATE DATABASE mysqltest1;
1432 USE mysqltest1;
1433 CREATE TABLE t1 (a INT);
1434 CREATE SQL SECURITY INVOKER VIEW v1 AS SELECT a FROM t1 GROUP BY a;
1435 CREATE SQL SECURITY INVOKER VIEW v2 AS SELECT a FROM v1;
1436 CREATE USER mysqluser1;
1437 GRANT SELECT ON TABLE t1 TO mysqluser1;
1438 GRANT SELECT, SHOW VIEW ON TABLE v1 TO mysqluser1;
1439 GRANT SELECT, SHOW VIEW ON TABLE v2 TO mysqluser1;
1440 SELECT a FROM v1;
1442 SELECT a FROM v2;
1444 DROP USER mysqluser1;
1445 DROP DATABASE mysqltest1;
1446 USE test;
1448 # Bug#47734: Assertion failed: ! is_set() when locking a view with non-existing definer
1450 DROP VIEW IF EXISTS v1;
1451 CREATE DEFINER=`unknown`@`unknown` SQL SECURITY DEFINER VIEW v1 AS SELECT 1;
1452 Warnings:
1453 Note    1449    The user specified as a definer ('unknown'@'unknown') does not exist
1454 LOCK TABLES v1 READ;
1455 ERROR HY000: The user specified as a definer ('unknown'@'unknown') does not exist
1456 DROP VIEW v1;
1458 # Bug #58499 "DEFINER-security view selecting from INVOKER-security view
1459 #             access check wrong".
1461 # Check that we correctly handle privileges for various combinations
1462 # of INVOKER and DEFINER-security views using each other.
1463 DROP DATABASE IF EXISTS mysqltest1;
1464 CREATE DATABASE mysqltest1;
1465 USE mysqltest1;
1466 CREATE TABLE t1 (i INT);
1467 CREATE TABLE t2 (j INT);
1468 INSERT INTO t1 VALUES (1);
1469 INSERT INTO t2 VALUES (2);
1471 # 1) DEFINER-security view uses INVOKER-security view (covers
1472 #    scenario originally described in the bug report).
1473 CREATE SQL SECURITY INVOKER VIEW v1_uses_t1 AS SELECT * FROM t1;
1474 CREATE SQL SECURITY INVOKER VIEW v1_uses_t2 AS SELECT * FROM t2;
1475 CREATE USER 'mysqluser1'@'%';
1476 GRANT CREATE VIEW ON mysqltest1.* TO 'mysqluser1'@'%';
1477 GRANT SELECT ON t1 TO 'mysqluser1'@'%';
1478 # To be able create 'v2_uses_t2' we also need select on t2. 
1479 GRANT SELECT ON t2 TO 'mysqluser1'@'%';
1480 GRANT SELECT ON v1_uses_t1 TO 'mysqluser1'@'%';
1481 GRANT SELECT ON v1_uses_t2 TO 'mysqluser1'@'%';
1483 # Connection 'mysqluser1'.
1484 CREATE SQL SECURITY DEFINER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1;
1485 CREATE SQL SECURITY DEFINER VIEW v2_uses_t2 AS SELECT * FROM v1_uses_t2;
1487 # Connection 'default'.
1488 CREATE USER 'mysqluser2'@'%';
1489 GRANT SELECT ON v2_uses_t1 TO 'mysqluser2'@'%';
1490 GRANT SELECT ON v2_uses_t2 TO 'mysqluser2'@'%';
1491 GRANT SELECT ON t2 TO 'mysqluser2'@'%';
1492 GRANT CREATE VIEW ON mysqltest1.* TO 'mysqluser2'@'%';
1493 # Make 'mysqluser1' unable to access t2.
1494 REVOKE SELECT ON t2 FROM 'mysqluser1'@'%';
1496 # Connection 'mysqluser2'.
1497 # The below statement should succeed thanks to suid nature of v2_uses_t1.
1498 SELECT * FROM v2_uses_t1;
1501 # The below statement should fail due to suid nature of v2_uses_t2.
1502 SELECT * FROM v2_uses_t2;
1503 ERROR HY000: View 'mysqltest1.v2_uses_t2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1505 # 2) INVOKER-security view uses INVOKER-security view.
1507 # Connection 'default'.
1508 DROP VIEW v2_uses_t1, v2_uses_t2;
1509 CREATE SQL SECURITY INVOKER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1;
1510 CREATE SQL SECURITY INVOKER VIEW v2_uses_t2 AS SELECT * FROM v1_uses_t2;
1511 GRANT SELECT ON v2_uses_t1 TO 'mysqluser1'@'%';
1512 GRANT SELECT ON v2_uses_t2 TO 'mysqluser1'@'%';
1513 GRANT SELECT ON v1_uses_t1 TO 'mysqluser2'@'%';
1514 GRANT SELECT ON v1_uses_t2 TO 'mysqluser2'@'%';
1516 # Connection 'mysqluser1'.
1517 # For both versions of 'v2' 'mysqluser1' privileges should be used.
1518 SELECT * FROM v2_uses_t1;
1521 SELECT * FROM v2_uses_t2;
1522 ERROR HY000: View 'mysqltest1.v2_uses_t2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1524 # Connection 'mysqluser2'.
1525 # And now for both versions of 'v2' 'mysqluser2' privileges should
1526 # be used.
1527 SELECT * FROM v2_uses_t1;
1528 ERROR HY000: View 'mysqltest1.v2_uses_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1529 SELECT * FROM v2_uses_t2;
1533 # 3) INVOKER-security view uses DEFINER-security view.
1535 # Connection 'default'.
1536 DROP VIEW v1_uses_t1, v1_uses_t2;
1537 # To be able create 'v1_uses_t2' we also need select on t2. 
1538 GRANT SELECT ON t2 TO 'mysqluser1'@'%';
1540 # Connection 'mysqluser1'.
1541 CREATE SQL SECURITY DEFINER VIEW v1_uses_t1 AS SELECT * FROM t1;
1542 CREATE SQL SECURITY DEFINER VIEW v1_uses_t2 AS SELECT * FROM t2;
1544 # Connection 'default'.
1545 # Make 'mysqluser1' unable to access t2.
1546 REVOKE SELECT ON t2 FROM 'mysqluser1'@'%';
1548 # Connection 'mysqluser2'.
1549 # Due to suid nature of v1_uses_t1 and v1_uses_t2 the first
1550 # select should succeed and the second select should fail.
1551 SELECT * FROM v2_uses_t1;
1554 SELECT * FROM v2_uses_t2;
1555 ERROR HY000: View 'mysqltest1.v2_uses_t2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1557 # 4) DEFINER-security view uses DEFINER-security view.
1559 # Connection 'default'.
1560 DROP VIEW v2_uses_t1, v2_uses_t2;
1561 # To be able create 'v2_uses_t2' we also need select on t2. 
1562 GRANT SELECT ON t2 TO 'mysqluser1'@'%';
1564 # Connection 'mysqluser2'.
1565 CREATE SQL SECURITY DEFINER VIEW v2_uses_t1 AS SELECT * FROM v1_uses_t1;
1566 CREATE SQL SECURITY DEFINER VIEW v2_uses_t2 AS SELECT * FROM v1_uses_t2;
1568 # Connection 'default'.
1569 # Make 'mysqluser1' unable to access t2.
1570 REVOKE SELECT ON t2 FROM 'mysqluser1'@'%';
1572 # Connection 'mysqluser2'.
1573 # Again privileges of creator of innermost views should apply.
1574 SELECT * FROM v2_uses_t1;
1577 SELECT * FROM v2_uses_t2;
1578 ERROR HY000: View 'mysqltest1.v2_uses_t2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
1579 USE test;
1580 DROP DATABASE mysqltest1;
1581 DROP USER 'mysqluser1'@'%';
1582 DROP USER 'mysqluser2'@'%';