~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to mysql-test/suite/funcs_1/r/falcon_trig_03e.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
USE test;
 
2
 
 
3
Testcase for db level:
 
4
----------------------
 
5
drop database if exists priv_db;
 
6
drop database if exists no_priv_db;
 
7
create database priv_db;
 
8
create database no_priv_db;
 
9
use priv_db;
 
10
create table t1 (f1 char(20)) engine= falcon;
 
11
create User test_yesprivs@localhost;
 
12
set password for test_yesprivs@localhost = password('PWD');
 
13
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
14
grant select on priv_db.* to test_yesprivs@localhost;
 
15
show grants for test_yesprivs@localhost;
 
16
Grants for test_yesprivs@localhost
 
17
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
18
GRANT SELECT ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
19
create User test_noprivs@localhost;
 
20
set password for test_noprivs@localhost = password('PWD');
 
21
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
22
grant select,insert on priv_db.* to test_noprivs@localhost;
 
23
show grants for test_noprivs@localhost;
 
24
Grants for test_noprivs@localhost
 
25
GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
26
GRANT SELECT, INSERT ON `priv_db`.* TO 'test_noprivs'@'localhost'
 
27
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
28
 
 
29
no trigger privilege on db level for create:
 
30
--------------------------------------------
 
31
use priv_db;
 
32
create trigger trg1_1 before INSERT on t1 for each row
 
33
set new.f1 = 'trig 1_1-no';
 
34
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
35
connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
36
use priv_db;
 
37
insert into t1 (f1) values ('insert-yes');
 
38
select f1 from t1 order by f1;
 
39
f1
 
40
insert-yes
 
41
select current_user;
 
42
current_user
 
43
root@localhost
 
44
grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 
45
show grants for test_yesprivs@localhost;
 
46
Grants for test_yesprivs@localhost
 
47
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
48
GRANT SELECT, TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
49
 
 
50
trigger privilege on db level for create:
 
51
-----------------------------------------
 
52
select current_user;
 
53
current_user
 
54
test_yesprivs@localhost
 
55
use priv_db;
 
56
create trigger trg1_2 before INSERT  on t1 for each row
 
57
set new.f1 = 'trig 1_2-yes';
 
58
select current_user;
 
59
current_user
 
60
test_noprivs@localhost
 
61
use priv_db;
 
62
insert into t1 (f1) values ('insert-yes');
 
63
ERROR 42000: UPDATE command denied to user 'test_yesprivs'@'localhost' for column 'f1' in table 't1'
 
64
select f1 from t1 order by f1;
 
65
f1
 
66
insert-yes
 
67
select current_user;
 
68
current_user
 
69
root@localhost
 
70
grant UPDATE on priv_db.* to test_yesprivs@localhost;
 
71
use priv_db;
 
72
insert into t1 (f1) values ('insert-no');
 
73
select f1 from t1 order by f1;
 
74
f1
 
75
insert-yes
 
76
trig 1_2-yes
 
77
select current_user;
 
78
current_user
 
79
test_noprivs@localhost
 
80
use priv_db;
 
81
insert into t1 (f1) values ('insert-yes');
 
82
select f1 from t1 order by f1;
 
83
f1
 
84
insert-yes
 
85
trig 1_2-yes
 
86
trig 1_2-yes
 
87
select current_user;
 
88
current_user
 
89
root@localhost
 
90
revoke TRIGGER on priv_db.* from test_yesprivs@localhost;
 
91
show grants for test_yesprivs@localhost;
 
92
Grants for test_yesprivs@localhost
 
93
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
94
GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
95
 
 
96
no trigger privilege on db level for drop:
 
97
------------------------------------------
 
98
select current_user;
 
99
current_user
 
100
test_yesprivs@localhost
 
101
use priv_db;
 
102
drop trigger trg1_2;
 
103
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
104
select current_user;
 
105
current_user
 
106
test_noprivs@localhost
 
107
use priv_db;
 
108
 
 
109
no trigger privilege at activation time:
 
110
----------------------------------------
 
111
insert into t1 (f1) values ('insert-yes');
 
112
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
113
select f1 from t1 order by f1;
 
114
f1
 
115
insert-yes
 
116
trig 1_2-yes
 
117
trig 1_2-yes
 
118
 
 
119
trigger privilege at activation time:
 
120
-------------------------------------
 
121
select current_user;
 
122
current_user
 
123
root@localhost
 
124
grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 
125
select current_user;
 
126
current_user
 
127
test_noprivs@localhost
 
128
use priv_db;
 
129
insert into t1 (f1) values ('insert-no');
 
130
select f1 from t1 order by f1;
 
131
f1
 
132
insert-yes
 
133
trig 1_2-yes
 
134
trig 1_2-yes
 
135
trig 1_2-yes
 
136
 
 
137
trigger privilege on db level for drop:
 
138
---------------------------------------
 
139
select current_user;
 
140
current_user
 
141
test_yesprivs@localhost
 
142
show grants for test_yesprivs@localhost;
 
143
Grants for test_yesprivs@localhost
 
144
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
145
GRANT SELECT, UPDATE, TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
146
drop trigger trg1_2;
 
147
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
148
 
 
149
takes effect after use priv_db:
 
150
-------------------------------
 
151
use priv_db;
 
152
drop trigger trg1_2;
 
153
select current_user;
 
154
current_user
 
155
root@localhost
 
156
use priv_db;
 
157
insert into t1 (f1) values ('insert-yes');
 
158
select f1 from t1 order by f1;
 
159
f1
 
160
insert-yes
 
161
insert-yes
 
162
trig 1_2-yes
 
163
trig 1_2-yes
 
164
trig 1_2-yes
 
165
 
 
166
switch to db without having trigger priv for it:
 
167
------------------------------------------------
 
168
use no_priv_db;
 
169
create table t1 (f1 char(20)) engine= falcon;
 
170
grant SELECT,UPDATE on no_priv_db.* to test_yesprivs@localhost;
 
171
show grants for test_yesprivs@localhost;
 
172
Grants for test_yesprivs@localhost
 
173
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
174
GRANT SELECT, UPDATE, TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
175
GRANT SELECT, UPDATE ON `no_priv_db`.* TO 'test_yesprivs'@'localhost'
 
176
 
 
177
use db with trigger privilege on db level and without...:
 
178
---------------------------------------------------------
 
179
select current_user;
 
180
current_user
 
181
test_yesprivs@localhost
 
182
use no_priv_db;
 
183
create trigger trg1_3 before INSERT  on t1 for each row
 
184
set new.f1 = 'trig 1_3-no';
 
185
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
186
use priv_db;
 
187
create trigger trg1_3 before INSERT  on t1 for each row
 
188
set new.f1 = 'trig 1_3-yes';
 
189
use no_priv_db;
 
190
create trigger trg1_4 before UPDATE  on t1 for each row
 
191
set new.f1 = 'trig 1_4-no';
 
192
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
193
use priv_db;
 
194
create trigger trg1_4 before UPDATE  on t1 for each row
 
195
set new.f1 = 'trig 1_4-yes';
 
196
select current_user;
 
197
current_user
 
198
test_noprivs@localhost
 
199
use no_priv_db;
 
200
ERROR 42000: Access denied for user 'test_noprivs'@'localhost' to database 'no_priv_db'
 
201
insert into t1 (f1) values ('insert-yes');
 
202
select f1 from t1 order by f1;
 
203
f1
 
204
insert-yes
 
205
insert-yes
 
206
trig 1_2-yes
 
207
trig 1_2-yes
 
208
trig 1_2-yes
 
209
trig 1_3-yes
 
210
use priv_db;
 
211
insert into t1 (f1) values ('insert-no');
 
212
select f1 from t1 order by f1;
 
213
f1
 
214
insert-yes
 
215
insert-yes
 
216
trig 1_2-yes
 
217
trig 1_2-yes
 
218
trig 1_2-yes
 
219
trig 1_3-yes
 
220
trig 1_3-yes
 
221
select current_user;
 
222
current_user
 
223
test_yesprivs@localhost
 
224
use no_priv_db;
 
225
drop trigger trg1_3;
 
226
ERROR HY000: Trigger does not exist
 
227
use priv_db;
 
228
drop trigger trg1_3;
 
229
use no_priv_db;
 
230
drop trigger trg1_4;
 
231
ERROR HY000: Trigger does not exist
 
232
use priv_db;
 
233
drop trigger trg1_4;
 
234
select current_user;
 
235
current_user
 
236
root@localhost
 
237
drop table priv_db.t1;
 
238
drop table no_priv_db.t1;
 
239
drop database if exists priv_db;
 
240
drop database if exists no_priv_db;
 
241
drop user test_yesprivs@localhost;
 
242
drop user test_noprivs@localhost;
 
243
 
 
244
#########      Testcase for table level:   ########
 
245
---------------------------------------------------
 
246
drop database if exists priv_db;
 
247
create database priv_db;
 
248
use priv_db;
 
249
create table t1 (f1 char(20)) engine= falcon;
 
250
create User test_yesprivs@localhost;
 
251
set password for test_yesprivs@localhost = password('PWD');
 
252
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
253
create User test_noprivs@localhost;
 
254
set password for test_noprivs@localhost = password('PWD');
 
255
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
256
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
257
connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
258
 
 
259
no trigger privilege on table level for create:
 
260
-----------------------------------------------
 
261
select current_user;
 
262
current_user
 
263
root@localhost
 
264
show triggers;
 
265
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
266
grant  select, insert, update on priv_db.t1 to test_yesprivs@localhost;
 
267
show grants for test_yesprivs@localhost;
 
268
Grants for test_yesprivs@localhost
 
269
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
270
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
271
grant select, update, insert on priv_db.t1 to test_noprivs@localhost;
 
272
show grants for test_noprivs@localhost;
 
273
Grants for test_noprivs@localhost
 
274
GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
275
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
 
276
select current_user;
 
277
current_user
 
278
test_yesprivs@localhost
 
279
use priv_db;
 
280
show tables;
 
281
Tables_in_priv_db
 
282
t1
 
283
create trigger trg1_1 before INSERT on t1 for each row
 
284
set new.f1 = 'trig 1_1-no';
 
285
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
286
select current_user;
 
287
current_user
 
288
test_noprivs@localhost
 
289
use priv_db;
 
290
insert into t1 (f1) values ('insert1-yes');
 
291
select f1 from t1 order by f1;
 
292
f1
 
293
insert1-yes
 
294
select current_user;
 
295
current_user
 
296
root@localhost
 
297
show triggers;
 
298
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
299
show tables;
 
300
Tables_in_priv_db
 
301
t1
 
302
insert into t1 (f1) values ('insert2-yes');
 
303
select f1 from t1 order by f1;
 
304
f1
 
305
insert1-yes
 
306
insert2-yes
 
307
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
 
308
show grants for test_yesprivs@localhost;
 
309
Grants for test_yesprivs@localhost
 
310
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
311
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
312
 
 
313
trigger privilege on table level for create:
 
314
--------------------------------------------
 
315
select current_user;
 
316
current_user
 
317
test_yesprivs@localhost
 
318
show triggers;
 
319
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
320
create trigger trg1_2 before INSERT  on t1 for each row
 
321
set new.f1 = 'trig 1_2-yes';
 
322
select current_user;
 
323
current_user
 
324
test_noprivs@localhost
 
325
insert into t1 (f1) values ('insert3-no');
 
326
select f1 from t1 order by f1;
 
327
f1
 
328
insert1-yes
 
329
insert2-yes
 
330
trig 1_2-yes
 
331
select current_user;
 
332
current_user
 
333
root@localhost
 
334
insert into t1 (f1) values ('insert4-no');
 
335
select f1 from t1 order by f1;
 
336
f1
 
337
insert1-yes
 
338
insert2-yes
 
339
trig 1_2-yes
 
340
trig 1_2-yes
 
341
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
342
show grants for test_yesprivs@localhost;
 
343
Grants for test_yesprivs@localhost
 
344
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
345
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
346
 
 
347
no trigger privilege on table level for drop:
 
348
---------------------------------------------
 
349
select current_user;
 
350
current_user
 
351
test_yesprivs@localhost
 
352
drop trigger trg1_2;
 
353
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
354
 
 
355
no trigger privilege at activation time:
 
356
----------------------------------------
 
357
select current_user;
 
358
current_user
 
359
test_noprivs@localhost
 
360
insert into t1 (f1) values ('insert5-no');
 
361
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
362
select f1 from t1 order by f1;
 
363
f1
 
364
insert1-yes
 
365
insert2-yes
 
366
trig 1_2-yes
 
367
trig 1_2-yes
 
368
select current_user;
 
369
current_user
 
370
root@localhost
 
371
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
 
372
 
 
373
trigger privilege at activation time:
 
374
-------------------------------------
 
375
select current_user;
 
376
current_user
 
377
test_noprivs@localhost
 
378
insert into t1 (f1) values ('insert6-no');
 
379
select f1 from t1 order by f1;
 
380
f1
 
381
insert1-yes
 
382
insert2-yes
 
383
trig 1_2-yes
 
384
trig 1_2-yes
 
385
trig 1_2-yes
 
386
 
 
387
trigger privilege on table level for drop:
 
388
------------------------------------------
 
389
select current_user;
 
390
current_user
 
391
test_yesprivs@localhost
 
392
show grants for test_yesprivs@localhost;
 
393
Grants for test_yesprivs@localhost
 
394
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
395
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
396
drop trigger trg1_2;
 
397
select current_user;
 
398
current_user
 
399
test_noprivs@localhost
 
400
insert into t1 (f1) values ('insert7-yes');
 
401
select f1 from t1 order by f1;
 
402
f1
 
403
insert1-yes
 
404
insert2-yes
 
405
insert7-yes
 
406
trig 1_2-yes
 
407
trig 1_2-yes
 
408
trig 1_2-yes
 
409
select current_user;
 
410
current_user
 
411
root@localhost
 
412
insert into t1 (f1) values ('insert8-yes');
 
413
select f1 from t1 order by f1;
 
414
f1
 
415
insert1-yes
 
416
insert2-yes
 
417
insert7-yes
 
418
insert8-yes
 
419
trig 1_2-yes
 
420
trig 1_2-yes
 
421
trig 1_2-yes
 
422
 
 
423
switch to table without having trigger priv for it:
 
424
---------------------------------------------------
 
425
create table t2 (f1 char(20)) engine= falcon;
 
426
grant SELECT, INSERT, UPDATE on priv_db.t2 to test_yesprivs@localhost;
 
427
show grants for test_yesprivs@localhost;
 
428
Grants for test_yesprivs@localhost
 
429
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
430
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 
431
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
432
grant SELECT, INSERT, UPDATE on priv_db.t2 to test_noprivs@localhost;
 
433
show grants for test_noprivs@localhost;
 
434
Grants for test_noprivs@localhost
 
435
GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
436
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_noprivs'@'localhost'
 
437
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t2` TO 'test_noprivs'@'localhost'
 
438
 
 
439
use table with trigger privilege and without...:
 
440
------------------------------------------------
 
441
select current_user;
 
442
current_user
 
443
test_yesprivs@localhost
 
444
create trigger trg2_1 before INSERT  on t2 for each row
 
445
set new.f1 = 'trig 2_1-no';
 
446
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
447
create trigger trg1_3 before INSERT  on t1 for each row
 
448
set new.f1 = 'trig 1_3-yes';
 
449
create trigger trg2_2 before UPDATE  on t2 for each row
 
450
set new.f1 = 'trig 2_2-no';
 
451
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
452
create trigger trg1_4 before UPDATE  on t1 for each row
 
453
set new.f1 = 'trig 1_4-yes';
 
454
show triggers;
 
455
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
456
trg1_3  INSERT  t1      set new.f1 = 'trig 1_3-yes'     BEFORE  NULL            test_yesprivs@localhost latin1  latin1_swedish_ci       latin1_swedish_ci
 
457
trg1_4  UPDATE  t1      set new.f1 = 'trig 1_4-yes'     BEFORE  NULL            test_yesprivs@localhost latin1  latin1_swedish_ci       latin1_swedish_ci
 
458
select current_user;
 
459
current_user
 
460
test_noprivs@localhost
 
461
insert into t2 (f1) values ('insert9-yes');
 
462
select f1 from t2 order by f1;
 
463
f1
 
464
insert9-yes
 
465
insert into t1 (f1) values ('insert10-no');
 
466
select f1 from t1 order by f1;
 
467
f1
 
468
insert1-yes
 
469
insert2-yes
 
470
insert7-yes
 
471
insert8-yes
 
472
trig 1_2-yes
 
473
trig 1_2-yes
 
474
trig 1_2-yes
 
475
trig 1_3-yes
 
476
select current_user;
 
477
current_user
 
478
test_yesprivs@localhost
 
479
drop trigger trg2_1;
 
480
ERROR HY000: Trigger does not exist
 
481
drop trigger trg1_3;
 
482
drop trigger trg2_2;
 
483
ERROR HY000: Trigger does not exist
 
484
drop trigger trg1_4;
 
485
select current_user;
 
486
current_user
 
487
root@localhost
 
488
drop database if exists priv_db;
 
489
drop user test_yesprivs@localhost;
 
490
drop user test_noprivs@localhost;
 
491
 
 
492
#### Testcase for mix of user(global) and db level: ####
 
493
--------------------------------------------------------
 
494
drop database if exists priv_db;
 
495
drop database if exists no_priv_db;
 
496
create database priv_db;
 
497
create database no_priv_db;
 
498
use priv_db;
 
499
create table t1 (f1 char(20)) engine= falcon;
 
500
use no_priv_db;
 
501
create table t1 (f1 char(20)) engine= falcon;
 
502
create User test_yesprivs@localhost;
 
503
set password for test_yesprivs@localhost = password('PWD');
 
504
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
505
grant ALL  on *.* to test_yesprivs@localhost;
 
506
show grants for test_yesprivs@localhost;
 
507
Grants for test_yesprivs@localhost
 
508
GRANT ALL PRIVILEGES ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
509
create User test_noprivs@localhost;
 
510
set password for test_noprivs@localhost = password('PWD');
 
511
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
512
grant SELECT,INSERT  on *.* to test_noprivs@localhost;
 
513
show grants for test_noprivs@localhost;
 
514
Grants for test_noprivs@localhost
 
515
GRANT SELECT, INSERT ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
516
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
517
connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
518
select current_user;
 
519
current_user
 
520
test_yesprivs@localhost
 
521
 
 
522
trigger privilege on user level for create:
 
523
-------------------------------------------
 
524
use priv_db;
 
525
create trigger trg1_1 before INSERT  on t1 for each row
 
526
set new.f1 = 'trig 1_1-yes';
 
527
insert into t1 (f1) values ('insert-no');
 
528
select f1 from t1 order by f1;
 
529
f1
 
530
trig 1_1-yes
 
531
use no_priv_db;
 
532
create trigger priv_db.trg1_5 before UPDATE  on priv_db.t1
 
533
for each row
 
534
set new.f1 = 'trig 1_5-yes';
 
535
insert into priv_db.t1 (f1) values ('insert-no');
 
536
select f1 from priv_db.t1 order by f1;
 
537
f1
 
538
trig 1_1-yes
 
539
trig 1_1-yes
 
540
drop trigger priv_db.trg1_5;
 
541
select current_user;
 
542
current_user
 
543
test_noprivs@localhost
 
544
use priv_db;
 
545
insert into t1 (f1) values ('insert-no');
 
546
select f1 from t1 order by f1;
 
547
f1
 
548
trig 1_1-yes
 
549
trig 1_1-yes
 
550
trig 1_1-yes
 
551
select current_user;
 
552
current_user
 
553
root@localhost
 
554
use priv_db;
 
555
insert into t1 (f1) values ('insert-no');
 
556
select f1 from t1 order by f1;
 
557
f1
 
558
trig 1_1-yes
 
559
trig 1_1-yes
 
560
trig 1_1-yes
 
561
trig 1_1-yes
 
562
revoke TRIGGER on *.* from test_yesprivs@localhost;
 
563
show grants for test_yesprivs@localhost;
 
564
Grants for test_yesprivs@localhost
 
565
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
566
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
567
select current_user;
 
568
current_user
 
569
test_yesprivs@localhost
 
570
use priv_db;
 
571
show triggers;
 
572
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
573
select * from information_schema.triggers;
 
574
TRIGGER_CATALOG TRIGGER_SCHEMA  TRIGGER_NAME    EVENT_MANIPULATION      EVENT_OBJECT_CATALOG    EVENT_OBJECT_SCHEMA     EVENT_OBJECT_TABLE      ACTION_ORDER    ACTION_CONDITION        ACTION_STATEMENT        ACTION_ORIENTATION      ACTION_TIMING   ACTION_REFERENCE_OLD_TABLE      ACTION_REFERENCE_NEW_TABLE      ACTION_REFERENCE_OLD_ROW        ACTION_REFERENCE_NEW_ROW        CREATED SQL_MODE        DEFINER CHARACTER_SET_CLIENT    COLLATION_CONNECTION    DATABASE_COLLATION
 
575
drop trigger trg1_1;
 
576
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
577
select current_user;
 
578
current_user
 
579
root@localhost
 
580
show grants;
 
581
Grants for root@localhost
 
582
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION
 
583
drop trigger trg1_1;
 
584
use priv_db;
 
585
 
 
586
no trigger privilege on db level for create:
 
587
--------------------------------------------
 
588
select current_user;
 
589
current_user
 
590
test_yesprivs@localhost
 
591
create trigger trg1_1 before INSERT on t1 for each row
 
592
set new.f1 = 'trig 1_1-no';
 
593
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
594
select current_user;
 
595
current_user
 
596
test_noprivs@localhost
 
597
use priv_db;
 
598
insert into t1 (f1) values ('insert-yes');
 
599
select f1 from t1 order by f1;
 
600
f1
 
601
insert-yes
 
602
trig 1_1-yes
 
603
trig 1_1-yes
 
604
trig 1_1-yes
 
605
trig 1_1-yes
 
606
select current_user;
 
607
current_user
 
608
root@localhost
 
609
grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 
610
show grants for test_yesprivs@localhost;
 
611
Grants for test_yesprivs@localhost
 
612
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
613
GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
614
 
 
615
trigger privilege on db level for create:
 
616
-----------------------------------------
 
617
select current_user;
 
618
current_user
 
619
test_yesprivs@localhost
 
620
use priv_db;
 
621
create trigger trg1_2 before INSERT  on t1 for each row
 
622
set new.f1 = 'trig 1_2-yes';
 
623
create trigger no_priv_db.trg1_9 before insert on no_priv_db.t1
 
624
for each row
 
625
set new.f1 = 'trig 1_9-yes';
 
626
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
627
use no_priv_db;
 
628
create trigger trg1_2 before INSERT  on t1 for each row
 
629
set new.f1 = 'trig 1_2-no';
 
630
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
631
create trigger priv_db.trg1_9 before UPDATE on priv_db.t1
 
632
for each row
 
633
set new.f1 = 'trig 1_9-yes';
 
634
select current_user;
 
635
current_user
 
636
test_noprivs@localhost
 
637
use priv_db;
 
638
insert into t1 (f1) values ('insert-yes');
 
639
select f1 from t1 order by f1;
 
640
f1
 
641
insert-yes
 
642
trig 1_1-yes
 
643
trig 1_1-yes
 
644
trig 1_1-yes
 
645
trig 1_1-yes
 
646
trig 1_2-yes
 
647
use no_priv_db;
 
648
insert into t1 (f1) values ('insert-yes');
 
649
select f1 from t1 order by f1;
 
650
f1
 
651
insert-yes
 
652
drop trigger priv_db.trg1_9;
 
653
ERROR 42000: TRIGGER command denied to user 'test_noprivs'@'localhost' for table 't1'
 
654
select current_user;
 
655
current_user
 
656
root@localhost
 
657
drop trigger priv_db.trg1_9;
 
658
revoke TRIGGER on priv_db.* from test_yesprivs@localhost;
 
659
use priv_db;
 
660
insert into t1 (f1) values ('insert-yes');
 
661
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
662
select f1 from t1 order by f1;
 
663
f1
 
664
insert-yes
 
665
trig 1_1-yes
 
666
trig 1_1-yes
 
667
trig 1_1-yes
 
668
trig 1_1-yes
 
669
trig 1_2-yes
 
670
grant TRIGGER on *.* to test_yesprivs@localhost;
 
671
show grants for test_yesprivs@localhost;
 
672
Grants for test_yesprivs@localhost
 
673
GRANT ALL PRIVILEGES ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
674
select current_user;
 
675
current_user
 
676
test_yesprivs@localhost
 
677
use no_priv_db;
 
678
create trigger trg1_2 before INSERT  on t1 for each row
 
679
set new.f1 = 'trig 1_2-no';
 
680
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
681
select current_user;
 
682
current_user
 
683
test_noprivs@localhost
 
684
use priv_db;
 
685
insert into t1 (f1) values ('insert-no');
 
686
select f1 from t1 order by f1;
 
687
f1
 
688
insert-yes
 
689
trig 1_1-yes
 
690
trig 1_1-yes
 
691
trig 1_1-yes
 
692
trig 1_1-yes
 
693
trig 1_2-yes
 
694
trig 1_2-yes
 
695
use no_priv_db;
 
696
insert into t1 (f1) values ('insert-yes');
 
697
select f1 from t1 order by f1;
 
698
f1
 
699
insert-yes
 
700
insert-yes
 
701
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
702
select current_user;
 
703
current_user
 
704
test_yesprivs@localhost
 
705
use no_priv_db;
 
706
create trigger trg1_2 before INSERT  on t1 for each row
 
707
set new.f1 = 'trig 1_2-yes';
 
708
select current_user;
 
709
current_user
 
710
test_noprivs@localhost
 
711
use priv_db;
 
712
insert into t1 (f1) values ('insert-no');
 
713
select f1 from t1 order by f1;
 
714
f1
 
715
insert-yes
 
716
trig 1_1-yes
 
717
trig 1_1-yes
 
718
trig 1_1-yes
 
719
trig 1_1-yes
 
720
trig 1_2-yes
 
721
trig 1_2-yes
 
722
trig 1_2-yes
 
723
use no_priv_db;
 
724
insert into t1 (f1) values ('insert-no');
 
725
select f1 from t1 order by f1;
 
726
f1
 
727
insert-yes
 
728
insert-yes
 
729
trig 1_2-yes
 
730
select current_user;
 
731
current_user
 
732
root@localhost
 
733
drop database if exists priv_db;
 
734
drop database if exists no_priv_db;
 
735
drop database if exists h1;
 
736
drop user test_yesprivs@localhost;
 
737
drop user test_noprivs@localhost;
 
738
 
 
739
####### Testcase for mix of db and table level: #######
 
740
-------------------------------------------------------
 
741
drop database if exists priv1_db;
 
742
drop database if exists priv2_db;
 
743
create database priv1_db;
 
744
create database priv2_db;
 
745
use priv1_db;
 
746
create table t1 (f1 char(20)) engine= falcon;
 
747
create table t2 (f1 char(20)) engine= falcon;
 
748
use priv2_db;
 
749
create table t1 (f1 char(20)) engine= falcon;
 
750
create User test_yesprivs@localhost;
 
751
set password for test_yesprivs@localhost = password('PWD');
 
752
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
753
grant ALL  on priv1_db.* to test_yesprivs@localhost;
 
754
grant SELECT,UPDATE on priv2_db.* to test_yesprivs@localhost;
 
755
show grants for test_yesprivs@localhost;
 
756
Grants for test_yesprivs@localhost
 
757
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
758
GRANT ALL PRIVILEGES ON `priv1_db`.* TO 'test_yesprivs'@'localhost'
 
759
GRANT SELECT, UPDATE ON `priv2_db`.* TO 'test_yesprivs'@'localhost'
 
760
create User test_noprivs@localhost;
 
761
set password for test_noprivs@localhost = password('PWD');
 
762
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
763
grant SELECT,INSERT,UPDATE on priv1_db.* to test_noprivs@localhost;
 
764
grant SELECT,INSERT on priv2_db.* to test_noprivs@localhost;
 
765
show grants for test_noprivs@localhost;
 
766
Grants for test_noprivs@localhost
 
767
GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
768
GRANT SELECT, INSERT, UPDATE ON `priv1_db`.* TO 'test_noprivs'@'localhost'
 
769
GRANT SELECT, INSERT ON `priv2_db`.* TO 'test_noprivs'@'localhost'
 
770
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
771
use priv1_db;
 
772
connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
773
use priv1_db;
 
774
 
 
775
trigger privilege on one db1 db level, not on db2
 
776
-------------------------------------------------
 
777
select current_user;
 
778
current_user
 
779
test_yesprivs@localhost
 
780
use priv1_db;
 
781
create trigger trg1_1 before INSERT  on t1 for each row
 
782
set new.f1 = 'trig 1_1-yes';
 
783
create trigger trg2_1 before INSERT  on t2 for each row
 
784
set new.f1 = 'trig 2_1-yes';
 
785
use priv2_db;
 
786
create trigger trg1_1 before INSERT  on t1 for each row
 
787
set new.f1 = 'trig1_1-yes';
 
788
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
789
select current_user;
 
790
current_user
 
791
test_noprivs@localhost
 
792
insert into t1 (f1) values ('insert1_no');
 
793
select f1 from t1 order by f1;
 
794
f1
 
795
trig 1_1-yes
 
796
insert into t2 (f1) values ('insert1_no');
 
797
select f1 from t2 order by f1;
 
798
f1
 
799
trig 2_1-yes
 
800
insert into priv2_db.t1 (f1) values ('insert21-yes');
 
801
select f1 from priv2_db.t1 order by f1;
 
802
f1
 
803
insert21-yes
 
804
use priv2_db;
 
805
insert into t1 (f1) values ('insert1_yes');
 
806
select f1 from t1 order by f1;
 
807
f1
 
808
insert1_yes
 
809
insert21-yes
 
810
insert into priv1_db.t1 (f1) values ('insert11-no');
 
811
select f1 from priv1_db.t1 order by f1;
 
812
f1
 
813
trig 1_1-yes
 
814
trig 1_1-yes
 
815
insert into priv1_db.t2 (f1) values ('insert22-no');
 
816
select f1 from priv1_db.t2 order by f1;
 
817
f1
 
818
trig 2_1-yes
 
819
trig 2_1-yes
 
820
 
 
821
revoke trigger privilege on table level (not existing)
 
822
------------------------------------------------------
 
823
select current_user;
 
824
current_user
 
825
root@localhost
 
826
use priv1_db;
 
827
revoke TRIGGER on priv1_db.t1 from test_yesprivs@localhost;
 
828
ERROR 42000: There is no such grant defined for user 'test_yesprivs' on host 'localhost' on table 't1'
 
829
show grants for test_yesprivs@localhost;
 
830
Grants for test_yesprivs@localhost
 
831
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
832
GRANT ALL PRIVILEGES ON `priv1_db`.* TO 'test_yesprivs'@'localhost'
 
833
GRANT SELECT, UPDATE ON `priv2_db`.* TO 'test_yesprivs'@'localhost'
 
834
select current_user;
 
835
current_user
 
836
test_yesprivs@localhost
 
837
drop trigger trg1_1;
 
838
ERROR HY000: Trigger does not exist
 
839
drop trigger trg2_1;
 
840
ERROR HY000: Trigger does not exist
 
841
use priv1_db;
 
842
drop trigger trg1_1;
 
843
drop trigger trg2_1;
 
844
select current_user;
 
845
current_user
 
846
root@localhost
 
847
use priv1_db;
 
848
revoke TRIGGER on priv1_db.* from test_yesprivs@localhost;
 
849
 
 
850
no trigger privilege on table level for create:
 
851
-----------------------------------------------
 
852
select current_user;
 
853
current_user
 
854
test_yesprivs@localhost
 
855
use priv1_db;
 
856
create trigger trg1_1 before INSERT on t1 for each row
 
857
set new.f1 = 'trig 1_1-no';
 
858
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
859
select current_user;
 
860
current_user
 
861
root@localhost
 
862
show triggers;
 
863
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
864
grant TRIGGER on priv1_db.t1 to test_yesprivs@localhost;
 
865
show grants for test_yesprivs@localhost;
 
866
Grants for test_yesprivs@localhost
 
867
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
868
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT ON `priv1_db`.* TO 'test_yesprivs'@'localhost'
 
869
GRANT SELECT, UPDATE ON `priv2_db`.* TO 'test_yesprivs'@'localhost'
 
870
GRANT TRIGGER ON `priv1_db`.`t1` TO 'test_yesprivs'@'localhost'
 
871
 
 
872
trigger privilege on table level for create:
 
873
--------------------------------------------
 
874
select current_user;
 
875
current_user
 
876
test_yesprivs@localhost
 
877
show triggers;
 
878
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
879
create trigger trg1_2 before INSERT  on t1 for each row
 
880
set new.f1 = 'trig 1_2-yes';
 
881
create trigger trg2_1 before INSERT  on t2 for each row
 
882
set new.f1 = 'trig 2_1-no';
 
883
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
884
select current_user;
 
885
current_user
 
886
test_noprivs@localhost
 
887
use priv1_db;
 
888
insert into t1 (f1) values ('insert2-no');
 
889
select f1 from t1 order by f1;
 
890
f1
 
891
trig 1_1-yes
 
892
trig 1_1-yes
 
893
trig 1_2-yes
 
894
insert into t2 (f1) values ('insert2-yes');
 
895
select f1 from t2 order by f1;
 
896
f1
 
897
insert2-yes
 
898
trig 2_1-yes
 
899
trig 2_1-yes
 
900
insert into priv2_db.t1 (f1) values ('insert22-yes');
 
901
select f1 from priv2_db.t1 order by f1;
 
902
f1
 
903
insert1_yes
 
904
insert21-yes
 
905
insert22-yes
 
906
select current_user;
 
907
current_user
 
908
root@localhost
 
909
grant TRIGGER on priv1_db.* to test_yesprivs@localhost;
 
910
show grants for test_yesprivs@localhost;
 
911
Grants for test_yesprivs@localhost
 
912
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
913
GRANT ALL PRIVILEGES ON `priv1_db`.* TO 'test_yesprivs'@'localhost'
 
914
GRANT SELECT, UPDATE ON `priv2_db`.* TO 'test_yesprivs'@'localhost'
 
915
GRANT TRIGGER ON `priv1_db`.`t1` TO 'test_yesprivs'@'localhost'
 
916
select current_user;
 
917
current_user
 
918
test_yesprivs@localhost
 
919
create trigger trg2_1 before INSERT  on t2 for each row
 
920
set new.f1 = 'trig 2_1-yes';
 
921
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
922
use priv1_db;
 
923
create trigger trg2_1 before INSERT  on t2 for each row
 
924
set new.f1 = 'trig 2_1-yes';
 
925
select current_user;
 
926
current_user
 
927
test_noprivs@localhost
 
928
use priv1_db;
 
929
insert into t1 (f1) values ('insert3-no');
 
930
select f1 from t1 order by f1;
 
931
f1
 
932
trig 1_1-yes
 
933
trig 1_1-yes
 
934
trig 1_2-yes
 
935
trig 1_2-yes
 
936
insert into t2 (f1) values ('insert3-no');
 
937
select f1 from t2 order by f1;
 
938
f1
 
939
insert2-yes
 
940
trig 2_1-yes
 
941
trig 2_1-yes
 
942
trig 2_1-yes
 
943
use priv2_db;
 
944
insert into priv1_db.t1 (f1) values ('insert12-no');
 
945
select f1 from priv1_db.t1 order by f1;
 
946
f1
 
947
trig 1_1-yes
 
948
trig 1_1-yes
 
949
trig 1_2-yes
 
950
trig 1_2-yes
 
951
trig 1_2-yes
 
952
insert into priv1_db.t2 (f1) values ('insert23-no');
 
953
select f1 from priv1_db.t2 order by f1;
 
954
f1
 
955
insert2-yes
 
956
trig 2_1-yes
 
957
trig 2_1-yes
 
958
trig 2_1-yes
 
959
trig 2_1-yes
 
960
select current_user;
 
961
current_user
 
962
test_yesprivs@localhost
 
963
drop trigger trg1_2;
 
964
drop trigger trg2_1;
 
965
select current_user;
 
966
current_user
 
967
root@localhost
 
968
drop database if exists priv1_db;
 
969
drop database if exists priv2_db;
 
970
drop user test_yesprivs@localhost;
 
971
drop user test_noprivs@localhost;
 
972
 
 
973
#### Testcase for trigger privilege on execution time ########
 
974
--------------------------------------------------------------
 
975
drop database if exists priv_db;
 
976
create database priv_db;
 
977
use priv_db;
 
978
create table t1 (f1 char(20)) engine= falcon;
 
979
create User test_yesprivs@localhost;
 
980
set password for test_yesprivs@localhost = password('PWD');
 
981
create User test_useprivs@localhost;
 
982
set password for test_useprivs@localhost = password('PWD');
 
983
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
984
revoke ALL PRIVILEGES, GRANT OPTION FROM test_useprivs@localhost;
 
985
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
986
select current_user;
 
987
current_user
 
988
root@localhost
 
989
show triggers;
 
990
Trigger Event   Table   Statement       Timing  Created sql_mode        Definer character_set_client    collation_connection    Database Collation
 
991
grant  select, insert, update ,trigger
 
992
on priv_db.t1 to test_yesprivs@localhost 
 
993
with grant option;
 
994
grant  select
 
995
on priv_db.t1 to test_useprivs@localhost;
 
996
show grants for test_yesprivs@localhost;
 
997
Grants for test_yesprivs@localhost
 
998
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
999
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1000
select current_user;
 
1001
current_user
 
1002
test_yesprivs@localhost
 
1003
use priv_db;
 
1004
create trigger trg1_1 before INSERT on t1 for each row
 
1005
set new.f1 = 'trig 1_1-yes';
 
1006
grant insert on t1 to test_useprivs@localhost;
 
1007
prepare ins1 from 'insert into t1 (f1) values (''insert1-no'')';
 
1008
execute ins1;
 
1009
select f1 from t1 order by f1;
 
1010
f1
 
1011
trig 1_1-yes
 
1012
prepare ins1 from 'insert into t1 (f1) values (''insert2-no'')';
 
1013
connect(localhost,test_useprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
1014
select current_user;
 
1015
current_user
 
1016
test_useprivs@localhost
 
1017
use priv_db;
 
1018
prepare ins1 from 'insert into t1 (f1) values (''insert3-no'')';
 
1019
execute ins1;
 
1020
select f1 from t1 order by f1;
 
1021
f1
 
1022
trig 1_1-yes
 
1023
trig 1_1-yes
 
1024
select current_user;
 
1025
current_user
 
1026
root@localhost
 
1027
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
1028
show grants for test_yesprivs@localhost;
 
1029
Grants for test_yesprivs@localhost
 
1030
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1031
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1032
select current_user;
 
1033
current_user
 
1034
test_yesprivs@localhost
 
1035
execute ins1;
 
1036
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1037
select f1 from t1 order by f1;
 
1038
f1
 
1039
trig 1_1-yes
 
1040
trig 1_1-yes
 
1041
prepare ins1 from 'insert into t1 (f1) values (''insert4-no'')';
 
1042
select current_user;
 
1043
current_user
 
1044
test_useprivs@localhost
 
1045
prepare ins1 from 'insert into t1 (f1) values (''insert5-no'')';
 
1046
execute ins1;
 
1047
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1048
select f1 from t1 order by f1;
 
1049
f1
 
1050
trig 1_1-yes
 
1051
trig 1_1-yes
 
1052
select current_user;
 
1053
current_user
 
1054
root@localhost
 
1055
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
 
1056
show grants for test_yesprivs@localhost;
 
1057
Grants for test_yesprivs@localhost
 
1058
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1059
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1060
select current_user;
 
1061
current_user
 
1062
test_yesprivs@localhost
 
1063
execute ins1;
 
1064
select f1 from t1 order by f1;
 
1065
f1
 
1066
trig 1_1-yes
 
1067
trig 1_1-yes
 
1068
trig 1_1-yes
 
1069
prepare ins1 from 'insert into t1 (f1) values (''insert6-no'')';
 
1070
select current_user;
 
1071
current_user
 
1072
test_useprivs@localhost
 
1073
execute ins1;
 
1074
select f1 from t1 order by f1;
 
1075
f1
 
1076
trig 1_1-yes
 
1077
trig 1_1-yes
 
1078
trig 1_1-yes
 
1079
trig 1_1-yes
 
1080
prepare ins1 from 'insert into t1 (f1) values (''insert7-no'')';
 
1081
select current_user;
 
1082
current_user
 
1083
root@localhost
 
1084
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
1085
show grants for test_yesprivs@localhost;
 
1086
Grants for test_yesprivs@localhost
 
1087
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1088
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1089
select current_user;
 
1090
current_user
 
1091
test_yesprivs@localhost
 
1092
execute ins1;
 
1093
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1094
select f1 from t1 order by f1;
 
1095
f1
 
1096
trig 1_1-yes
 
1097
trig 1_1-yes
 
1098
trig 1_1-yes
 
1099
trig 1_1-yes
 
1100
select current_user;
 
1101
current_user
 
1102
test_useprivs@localhost
 
1103
execute ins1;
 
1104
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1105
select f1 from t1 order by f1;
 
1106
f1
 
1107
trig 1_1-yes
 
1108
trig 1_1-yes
 
1109
trig 1_1-yes
 
1110
trig 1_1-yes
 
1111
select current_user;
 
1112
current_user
 
1113
root@localhost
 
1114
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
 
1115
show grants for test_yesprivs@localhost;
 
1116
Grants for test_yesprivs@localhost
 
1117
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1118
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1119
select current_user;
 
1120
current_user
 
1121
test_yesprivs@localhost
 
1122
execute ins1;
 
1123
select f1 from t1 order by f1;
 
1124
f1
 
1125
trig 1_1-yes
 
1126
trig 1_1-yes
 
1127
trig 1_1-yes
 
1128
trig 1_1-yes
 
1129
trig 1_1-yes
 
1130
select current_user;
 
1131
current_user
 
1132
test_useprivs@localhost
 
1133
execute ins1;
 
1134
select f1 from t1 order by f1;
 
1135
f1
 
1136
trig 1_1-yes
 
1137
trig 1_1-yes
 
1138
trig 1_1-yes
 
1139
trig 1_1-yes
 
1140
trig 1_1-yes
 
1141
trig 1_1-yes
 
1142
select current_user;
 
1143
current_user
 
1144
root@localhost
 
1145
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
1146
show grants for test_yesprivs@localhost;
 
1147
Grants for test_yesprivs@localhost
 
1148
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1149
GRANT SELECT, INSERT, UPDATE ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1150
select current_user;
 
1151
current_user
 
1152
test_yesprivs@localhost
 
1153
execute ins1;
 
1154
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1155
select f1 from t1 order by f1;
 
1156
f1
 
1157
trig 1_1-yes
 
1158
trig 1_1-yes
 
1159
trig 1_1-yes
 
1160
trig 1_1-yes
 
1161
trig 1_1-yes
 
1162
trig 1_1-yes
 
1163
deallocate prepare ins1;
 
1164
select current_user;
 
1165
current_user
 
1166
test_useprivs@localhost
 
1167
execute ins1;
 
1168
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1169
select f1 from t1 order by f1;
 
1170
f1
 
1171
trig 1_1-yes
 
1172
trig 1_1-yes
 
1173
trig 1_1-yes
 
1174
trig 1_1-yes
 
1175
trig 1_1-yes
 
1176
trig 1_1-yes
 
1177
deallocate prepare ins1;
 
1178
select current_user;
 
1179
current_user
 
1180
root@localhost
 
1181
grant TRIGGER on priv_db.t1 to test_yesprivs@localhost;
 
1182
show grants for test_yesprivs@localhost;
 
1183
Grants for test_yesprivs@localhost
 
1184
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1185
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1186
select current_user;
 
1187
current_user
 
1188
test_yesprivs@localhost
 
1189
drop trigger trg1_1;
 
1190
select current_user;
 
1191
current_user
 
1192
root@localhost
 
1193
select current_user;
 
1194
current_user
 
1195
root@localhost
 
1196
drop database if exists priv_db;
 
1197
drop user test_yesprivs@localhost;
 
1198
drop user test_useprivs@localhost;
 
1199
 
 
1200
#########      Testcase for definer:   ########
 
1201
-----------------------------------------------
 
1202
drop database if exists priv_db;
 
1203
create database priv_db;
 
1204
use priv_db;
 
1205
create table t1 (f1 char(20)) engine= falcon;
 
1206
create User test_yesprivs@localhost;
 
1207
set password for test_yesprivs@localhost = password('PWD');
 
1208
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
1209
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
1210
select current_user;
 
1211
current_user
 
1212
root@localhost
 
1213
create definer=not_ex_user@localhost trigger trg1_0
 
1214
before INSERT on t1 for each row
 
1215
set new.f1 = 'trig 1_0-yes';
 
1216
Warnings:
 
1217
Note    1449    There is no 'not_ex_user'@'localhost' registered
 
1218
drop trigger trg1_0;
 
1219
create definer=test_yesprivs@localhost trigger trg1_0
 
1220
before INSERT on t1 for each row
 
1221
set new.f1 = 'trig 1_0-yes';
 
1222
grant  select, insert, update
 
1223
on priv_db.t1 to test_yesprivs@localhost;
 
1224
select current_user;
 
1225
current_user
 
1226
test_yesprivs@localhost
 
1227
use priv_db;
 
1228
insert into t1 (f1) values ('insert-no');
 
1229
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1230
select f1 from t1 order by f1;
 
1231
f1
 
1232
drop trigger trg1_0;
 
1233
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1234
select current_user;
 
1235
current_user
 
1236
root@localhost
 
1237
grant  select, insert, update ,trigger
 
1238
on priv_db.t1 to test_yesprivs@localhost;
 
1239
show grants for test_yesprivs@localhost;
 
1240
Grants for test_yesprivs@localhost
 
1241
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1242
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1243
select current_user;
 
1244
current_user
 
1245
test_yesprivs@localhost
 
1246
insert into t1 (f1) values ('insert-no');
 
1247
select f1 from t1 order by f1;
 
1248
f1
 
1249
trig 1_0-yes
 
1250
drop trigger trg1_0;
 
1251
create definer=not_ex_user@localhost trigger trg1_0
 
1252
before INSERT on t1 for each row
 
1253
set new.f1 = 'trig 1_0-yes';
 
1254
ERROR 42000: Access denied; you need the SUPER privilege for this operation
 
1255
create definer=current_user trigger trg1_1 
 
1256
before INSERT on t1 for each row
 
1257
set new.f1 = 'trig 1_1-yes';
 
1258
insert into t1 (f1) values ('insert-no');
 
1259
select f1 from t1 order by f1;
 
1260
f1
 
1261
trig 1_0-yes
 
1262
trig 1_1-yes
 
1263
create definer=test_yesprivs@localhost trigger trg1_2
 
1264
before UPDATE on t1 for each row
 
1265
set new.f1 = 'trig 1_2-yes';
 
1266
update t1 set f1 = 'update-yes' where f1 like '%trig%';
 
1267
select f1 from t1 order by f1;
 
1268
f1
 
1269
trig 1_2-yes
 
1270
trig 1_2-yes
 
1271
select current_user;
 
1272
current_user
 
1273
root@localhost
 
1274
grant trigger on priv_db.* to test_yesprivs@localhost
 
1275
with grant option;
 
1276
select current_user;
 
1277
current_user
 
1278
test_yesprivs@localhost
 
1279
show grants;
 
1280
Grants for test_yesprivs@localhost
 
1281
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1282
GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost' WITH GRANT OPTION
 
1283
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1284
create definer=not_ex_user@localhost trigger trg1_3
 
1285
after UPDATE on t1 for each row
 
1286
set @var1 = 'trig 1_3-yes';
 
1287
ERROR 42000: Access denied; you need the SUPER privilege for this operation
 
1288
select current_user;
 
1289
current_user
 
1290
root@localhost
 
1291
select current_user;
 
1292
current_user
 
1293
root@localhost
 
1294
drop database if exists priv_db;
 
1295
drop user test_yesprivs@localhost;
 
1296
 
 
1297
#########      Testcase for transactions:   ########
 
1298
----------------------------------------------------
 
1299
drop database if exists priv_db;
 
1300
create database priv_db;
 
1301
use priv_db;
 
1302
create table t1 (f1 char(20)) engine= falcon;
 
1303
create User test_yesprivs@localhost;
 
1304
set password for test_yesprivs@localhost = password('PWD');
 
1305
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
1306
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
1307
select current_user;
 
1308
current_user
 
1309
root@localhost
 
1310
grant  select, insert, update ,trigger
 
1311
on priv_db.t1 to test_yesprivs@localhost;
 
1312
show grants for test_yesprivs@localhost;
 
1313
Grants for test_yesprivs@localhost
 
1314
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1315
GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1316
select current_user;
 
1317
current_user
 
1318
test_yesprivs@localhost
 
1319
use priv_db;
 
1320
set autocommit=0;
 
1321
create definer=current_user trigger trg1_1 
 
1322
before INSERT on t1 for each row
 
1323
set new.f1 = 'trig 1_1-yes';
 
1324
rollback work;
 
1325
insert into t1 (f1) values ('insert-no');
 
1326
select f1 from t1 order by f1;
 
1327
f1
 
1328
trig 1_1-yes
 
1329
create definer=test_yesprivs@localhost trigger trg1_2
 
1330
before UPDATE on t1 for each row
 
1331
set new.f1 = 'trig 1_2-yes';
 
1332
commit work;
 
1333
update t1 set f1 = 'update-yes' where f1 like '%trig%';
 
1334
select f1 from t1 order by f1;
 
1335
f1
 
1336
trig 1_2-yes
 
1337
commit work;
 
1338
drop trigger trg1_1;
 
1339
rollback work;
 
1340
drop trigger trg1_1;
 
1341
ERROR HY000: Trigger does not exist
 
1342
drop trigger trg1_2;
 
1343
commit work;
 
1344
set autocommit=1;
 
1345
select current_user;
 
1346
current_user
 
1347
root@localhost
 
1348
select current_user;
 
1349
current_user
 
1350
root@localhost
 
1351
drop database if exists priv_db;
 
1352
drop user test_yesprivs@localhost;
 
1353
 
 
1354
####### Testcase for column privileges of triggers: #######
 
1355
-----------------------------------------------------------
 
1356
drop database if exists priv_db;
 
1357
drop database if exists no_priv_db;
 
1358
create database priv_db;
 
1359
use priv_db;
 
1360
create table t1 (f1 char(20)) engine= falcon;
 
1361
create table t2 (f1 char(20)) engine= falcon;
 
1362
create User test_yesprivs@localhost;
 
1363
set password for test_yesprivs@localhost = password('PWD');
 
1364
revoke ALL PRIVILEGES, GRANT OPTION FROM test_yesprivs@localhost;
 
1365
grant TRIGGER on priv_db.* to test_yesprivs@localhost;
 
1366
show grants for test_yesprivs@localhost;
 
1367
Grants for test_yesprivs@localhost
 
1368
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1369
GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
1370
create User test_noprivs@localhost;
 
1371
set password for test_noprivs@localhost = password('PWD');
 
1372
revoke ALL PRIVILEGES, GRANT OPTION FROM test_noprivs@localhost;
 
1373
grant SELECT,UPDATE on priv_db.* to test_noprivs@localhost;
 
1374
show grants for test_noprivs@localhost;
 
1375
Grants for test_noprivs@localhost
 
1376
GRANT USAGE ON *.* TO 'test_noprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1377
GRANT SELECT, UPDATE ON `priv_db`.* TO 'test_noprivs'@'localhost'
 
1378
connect(localhost,test_yesprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
1379
connect(localhost,test_noprivs,PWD,test,MASTER_MYPORT,MASTER_MYSOCK);
 
1380
 
 
1381
update only on column:
 
1382
----------------------
 
1383
select current_user;
 
1384
current_user
 
1385
root@localhost
 
1386
grant SELECT(f1),INSERT,UPDATE(f1) on priv_db.t1
 
1387
to test_yesprivs@localhost;
 
1388
grant SELECT(f1),INSERT,UPDATE(f1) on priv_db.t2
 
1389
to test_yesprivs@localhost;
 
1390
select current_user;
 
1391
current_user
 
1392
test_yesprivs@localhost
 
1393
use priv_db;
 
1394
insert into t1 (f1) values ('insert1-yes');
 
1395
insert into t2 (f1) values ('insert1-yes');
 
1396
create trigger trg1_1 before UPDATE on t1 for each row
 
1397
set new.f1 = 'trig 1_1-yes';
 
1398
create trigger trg2_1 before UPDATE on t2 for each row
 
1399
set new.f1 = 'trig 2_1-yes';
 
1400
select current_user;
 
1401
current_user
 
1402
test_noprivs@localhost
 
1403
use priv_db;
 
1404
select f1 from t1 order by f1;
 
1405
f1
 
1406
insert1-yes
 
1407
update t1 set f1 = 'update1_no'
 
1408
                where f1 like '%insert%';
 
1409
select f1 from t1 order by f1;
 
1410
f1
 
1411
trig 1_1-yes
 
1412
select f1 from t2 order by f1;
 
1413
f1
 
1414
insert1-yes
 
1415
update t2 set f1 = 'update1_no'
 
1416
                where f1 like '%insert%';
 
1417
select f1 from t2 order by f1;
 
1418
f1
 
1419
trig 2_1-yes
 
1420
select current_user;
 
1421
current_user
 
1422
root@localhost
 
1423
revoke UPDATE     on priv_db.*
 
1424
from test_yesprivs@localhost;
 
1425
revoke UPDATE(f1) on priv_db.t2
 
1426
from test_yesprivs@localhost;
 
1427
show grants for test_yesprivs@localhost;
 
1428
Grants for test_yesprivs@localhost
 
1429
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1430
GRANT TRIGGER ON `priv_db`.* TO 'test_yesprivs'@'localhost'
 
1431
GRANT SELECT (f1), INSERT ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 
1432
GRANT SELECT (f1), INSERT, UPDATE (f1) ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1433
select current_user;
 
1434
current_user
 
1435
test_yesprivs@localhost
 
1436
use priv_db;
 
1437
insert into t1 (f1) values ('insert2-yes');
 
1438
insert into t2 (f1) values ('insert2-yes');
 
1439
select current_user;
 
1440
current_user
 
1441
test_noprivs@localhost
 
1442
use priv_db;
 
1443
update t1 set f1 = 'update2_no'
 
1444
                where f1 like '%insert%';
 
1445
update t2 set f1 = 'update2_no'
 
1446
                where f1 like '%insert%';
 
1447
ERROR 42000: UPDATE command denied to user 'test_yesprivs'@'localhost' for column 'f1' in table 't2'
 
1448
update t1 set f1 = 'update3_no'
 
1449
                where f1 like '%insert%';
 
1450
update t2 set f1 = 'update3_no'
 
1451
                where f1 like '%insert%';
 
1452
ERROR 42000: UPDATE command denied to user 'test_yesprivs'@'localhost' for column 'f1' in table 't2'
 
1453
select f1 from t1 order by f1;
 
1454
f1
 
1455
trig 1_1-yes
 
1456
trig 1_1-yes
 
1457
select f1 from t2 order by f1;
 
1458
f1
 
1459
insert2-yes
 
1460
trig 2_1-yes
 
1461
 
 
1462
check if access only on one of three columns
 
1463
--------------------------------------------
 
1464
select current_user;
 
1465
current_user
 
1466
root@localhost
 
1467
alter table priv_db.t1 add f2 char(20), add f3 int;
 
1468
revoke TRIGGER on priv_db.* from test_yesprivs@localhost;
 
1469
grant TRIGGER,SELECT on priv_db.t1 to test_yesprivs@localhost;
 
1470
grant UPDATE on priv_db.t2 to test_yesprivs@localhost;
 
1471
select current_user;
 
1472
current_user
 
1473
test_yesprivs@localhost
 
1474
use priv_db;
 
1475
insert into t1 values ('insert2-yes','insert2-yes',1);
 
1476
insert into t1 values ('insert3-yes','insert3-yes',2);
 
1477
select * from t1 order by f1;
 
1478
f1      f2      f3
 
1479
insert2-yes     insert2-yes     1
 
1480
insert3-yes     insert3-yes     2
 
1481
trig 1_1-yes    NULL    NULL
 
1482
trig 1_1-yes    NULL    NULL
 
1483
select current_user;
 
1484
current_user
 
1485
test_noprivs@localhost
 
1486
use priv_db;
 
1487
update t1 set   f1 = 'update4-no',
 
1488
f2 = 'update4-yes',
 
1489
f3 = f3*10
 
1490
where f2 like '%yes';
 
1491
select * from t1 order by f1,f2,f3;
 
1492
f1      f2      f3
 
1493
trig 1_1-yes    NULL    NULL
 
1494
trig 1_1-yes    NULL    NULL
 
1495
trig 1_1-yes    update4-yes     10
 
1496
trig 1_1-yes    update4-yes     20
 
1497
select current_user;
 
1498
current_user
 
1499
test_yesprivs@localhost
 
1500
create trigger trg1_2 after UPDATE on t1 for each row
 
1501
set @f2 = 'trig 1_2-yes';
 
1502
select current_user;
 
1503
current_user
 
1504
test_noprivs@localhost
 
1505
update t1 set   f1 = 'update5-yes',
 
1506
f2 = 'update5-yes'
 
1507
                where f2 like '%yes';
 
1508
select * from t1 order by f1,f2,f3;
 
1509
f1      f2      f3
 
1510
trig 1_1-yes    NULL    NULL
 
1511
trig 1_1-yes    NULL    NULL
 
1512
trig 1_1-yes    update5-yes     10
 
1513
trig 1_1-yes    update5-yes     20
 
1514
select @f2;
 
1515
@f2
 
1516
trig 1_2-yes
 
1517
update t1 set f1 = 'update6_no'
 
1518
                where f1 like '%insert%';
 
1519
update t2 set f1 = 'update6_no'
 
1520
                where f1 like '%insert%';
 
1521
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
1522
update t1 set f1 = 'update7_no'
 
1523
                where f1 like '%insert%';
 
1524
update t2 set f1 = 'update7_no'
 
1525
                where f1 like '%insert%';
 
1526
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't2'
 
1527
select f1 from t1 order by f1;
 
1528
f1
 
1529
trig 1_1-yes
 
1530
trig 1_1-yes
 
1531
trig 1_1-yes
 
1532
trig 1_1-yes
 
1533
select f1 from t2 order by f1;
 
1534
f1
 
1535
insert2-yes
 
1536
trig 2_1-yes
 
1537
 
 
1538
check if rejected without trigger privilege:
 
1539
--------------------------------------------
 
1540
select current_user;
 
1541
current_user
 
1542
root@localhost
 
1543
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
1544
select current_user;
 
1545
current_user
 
1546
test_noprivs@localhost
 
1547
update t1 set   f1 = 'update8-no',
 
1548
f2 = 'update8-no'
 
1549
                where f2 like '%yes';
 
1550
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1551
select * from t1 order by f1,f2,f3;
 
1552
f1      f2      f3
 
1553
trig 1_1-yes    NULL    NULL
 
1554
trig 1_1-yes    NULL    NULL
 
1555
trig 1_1-yes    update5-yes     10
 
1556
trig 1_1-yes    update5-yes     20
 
1557
select @f2;
 
1558
@f2
 
1559
trig 1_2-yes
 
1560
 
 
1561
check trigger, but not update privilege on column:
 
1562
--------------------------------------------------
 
1563
select current_user;
 
1564
current_user
 
1565
root@localhost
 
1566
revoke UPDATE(f1) on priv_db.t1 from test_yesprivs@localhost;
 
1567
grant TRIGGER,UPDATE(f2),UPDATE(f3) on priv_db.t1 
 
1568
to test_yesprivs@localhost;
 
1569
show grants for test_yesprivs@localhost;
 
1570
Grants for test_yesprivs@localhost
 
1571
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1572
GRANT SELECT (f1), INSERT, UPDATE ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 
1573
GRANT SELECT, SELECT (f1), INSERT, UPDATE (f3, f2), TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1574
select current_user;
 
1575
current_user
 
1576
test_yesprivs@localhost
 
1577
use priv_db;
 
1578
drop trigger trg1_1;
 
1579
create trigger trg1_3 before UPDATE on t1 for each row
 
1580
set new.f1 = 'trig 1_3-yes';
 
1581
select current_user;
 
1582
current_user
 
1583
test_noprivs@localhost
 
1584
use priv_db;
 
1585
update t1 set   f1 = 'update9-no',
 
1586
f2 = 'update9-no'
 
1587
                where f2 like '%yes';
 
1588
ERROR 42000: UPDATE command denied to user 'test_yesprivs'@'localhost' for column 'f1' in table 't1'
 
1589
select * from t1 order by f1,f2,f3;
 
1590
f1      f2      f3
 
1591
trig 1_1-yes    NULL    NULL
 
1592
trig 1_1-yes    NULL    NULL
 
1593
trig 1_1-yes    update5-yes     10
 
1594
trig 1_1-yes    update5-yes     20
 
1595
update t1 set f3= f3+1;
 
1596
ERROR 42000: UPDATE command denied to user 'test_yesprivs'@'localhost' for column 'f1' in table 't1'
 
1597
select f3 from t1 order by f3;
 
1598
f3
 
1599
NULL
 
1600
NULL
 
1601
10
 
1602
20
 
1603
select current_user;
 
1604
current_user
 
1605
root@localhost
 
1606
revoke TRIGGER on priv_db.t1 from test_yesprivs@localhost;
 
1607
grant UPDATE(f1),UPDATE(f2),UPDATE(f3) on priv_db.t1
 
1608
to test_yesprivs@localhost;
 
1609
show grants for test_yesprivs@localhost;
 
1610
Grants for test_yesprivs@localhost
 
1611
GRANT USAGE ON *.* TO 'test_yesprivs'@'localhost' IDENTIFIED BY PASSWORD '*C49735D016A099C0CF104EF9183F374A54CA2576'
 
1612
GRANT SELECT (f1), INSERT, UPDATE ON `priv_db`.`t2` TO 'test_yesprivs'@'localhost'
 
1613
GRANT SELECT, SELECT (f1), INSERT, UPDATE (f3, f2, f1) ON `priv_db`.`t1` TO 'test_yesprivs'@'localhost'
 
1614
select current_user;
 
1615
current_user
 
1616
test_noprivs@localhost
 
1617
use priv_db;
 
1618
update t1 set f3= f3+1;
 
1619
ERROR 42000: TRIGGER command denied to user 'test_yesprivs'@'localhost' for table 't1'
 
1620
select f3 from t1 order by f3;
 
1621
f3
 
1622
NULL
 
1623
NULL
 
1624
10
 
1625
20
 
1626
 
 
1627
##### trigger privilege on column level? #######
 
1628
------------------------------------------------
 
1629
grant TRIGGER(f1) on priv_db.t1 to test_yesprivs@localhost;
 
1630
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(f1) on priv_db.t1 to test_yesprivs@localhost' at line 1
 
1631
select current_user;
 
1632
current_user
 
1633
root@localhost
 
1634
drop database if exists priv_db;
 
1635
drop user test_yesprivs@localhost;
 
1636
drop user test_noprivs@localhost;