You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1710 lines
54 KiB

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