1set sql_mode=""; 2drop database if exists events_test; 3create database events_test; 4use events_test; 5create event e_26 on schedule at '2037-01-01 00:00:00' disable do set @a = 5; 6Warnings: 7Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 8select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event; 9db name body definer convert_tz(execute_at, 'UTC', 'SYSTEM') on_completion 10events_test e_26 set @a = 5 root@localhost 2037-01-01 00:00:00 DROP 11drop event e_26; 12create event e_26 on schedule at NULL disable do set @a = 5; 13ERROR HY000: Incorrect AT value: 'NULL' 14create event e_26 on schedule at 'definitely not a datetime' disable do set @a = 5; 15ERROR HY000: Incorrect AT value: 'definitely not a datetime' 16set names utf8; 17create event задачка on schedule every 123 minute starts now() ends now() + interval 1 month do select 1; 18Warnings: 19Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 20drop event задачка; 21"DISABLE the scheduler. Testing that it does not work when the variable is 0" 22set global event_scheduler=off; 23select definer, name, db from mysql.event; 24definer name db 25select get_lock("test_lock1", 20); 26get_lock("test_lock1", 20) 271 28create event закачка on schedule every 10 hour do select get_lock("test_lock1", 20); 29Warnings: 30Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 31"Should return 1 row" 32select definer, name, db from mysql.event; 33definer name db 34root@localhost закачка events_test 35"Should be only 0 process" 36select /*1*/ user, host, db, command, state, info 37from information_schema.processlist 38where (user='event_scheduler') 39order by info; 40user host db command state info 41select release_lock("test_lock1"); 42release_lock("test_lock1") 431 44drop event закачка; 45"Should have 0 events" 46select count(*) from mysql.event; 47count(*) 480 49"ENABLE the scheduler and get a lock" 50set global event_scheduler=on; 51select get_lock("test_lock2", 20); 52get_lock("test_lock2", 20) 531 54"Create an event which tries to acquire a mutex. The event locks on the mutex" 55create event закачка on schedule every 10 hour do select get_lock("test_lock2", 20); 56"Should have only 2 processes: the scheduler and the locked event" 57select /*2*/ user, host, db, command, state, info 58from information_schema.processlist 59where (info like "select get_lock%" OR user='event_scheduler') 60order by info; 61user host db command state info 62event_scheduler localhost NULL Daemon Waiting for next activation NULL 63root localhost events_test Connect User lock select get_lock("test_lock2", 20) 64"Release the mutex, the event worker should finish." 65select release_lock("test_lock2"); 66release_lock("test_lock2") 671 68drop event закачка; 69set global event_scheduler=1; 70select get_lock("test_lock2_1", 20); 71get_lock("test_lock2_1", 20) 721 73create event закачка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20); 74"Should have only 2 processes: the scheduler and the locked event" 75select /*3*/ user, host, db, command, state, info 76from information_schema.processlist 77where (info like "select get_lock%" OR user='event_scheduler') 78order by info; 79user host db command state info 80event_scheduler localhost NULL Daemon Waiting for next activation NULL 81root localhost events_test Connect User lock select get_lock("test_lock2_1", 20) 82set global event_scheduler=off; 83"Should have only our process now:" 84select /*4*/ user, host, db, command, state, info 85from information_schema.processlist 86where (info like "select get_lock%" OR user='event_scheduler') 87order by info; 88user host db command state info 89root localhost events_test Connect User lock select get_lock("test_lock2_1", 20) 90select release_lock("test_lock2_1"); 91release_lock("test_lock2_1") 921 93drop event закачка21; 94create table t_16 (s1 int); 95create trigger t_16_bi before insert on t_16 for each row create event e_16 on schedule every 1 second do set @a=5; 96ERROR HY000: Recursion of EVENT DDL statements is forbidden when body is present 97drop table t_16; 98create event white_space 99on schedule every 10 hour 100disable 101do 102select 1; 103Warnings: 104Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 105select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space'; 106event_schema event_name definer event_definition 107events_test white_space root@localhost select 1 108drop event white_space; 109create event white_space on schedule every 10 hour disable do 110select 2; 111Warnings: 112Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 113select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space'; 114event_schema event_name definer event_definition 115events_test white_space root@localhost select 2 116drop event white_space; 117create event white_space on schedule every 10 hour disable do select 3; 118Warnings: 119Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 120select event_schema, event_name, definer, event_definition from information_schema.events where event_name='white_space'; 121event_schema event_name definer event_definition 122events_test white_space root@localhost select 3 123drop event white_space; 124create event e1 on schedule every 1 year do set @a = 5; 125Warnings: 126Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 127create table t1 (s1 int); 128create trigger t1_ai after insert on t1 for each row show create event e1; 129ERROR 0A000: Not allowed to return a result set from a trigger 130drop table t1; 131drop event e1; 132SHOW EVENTS FROM aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; 133ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 134SHOW EVENTS FROM ``; 135ERROR 42000: Incorrect database name '' 136SHOW EVENTS FROM `events\\test`; 137Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation 138 139LOCK TABLES mode. 140 141create table t1 (a int); 142create event e1 on schedule every 10 hour do select 1; 143Warnings: 144Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 145lock table t1 read; 146show create event e1; 147Event sql_mode time_zone Create Event character_set_client collation_connection Database Collation 148e1 SYSTEM CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1 utf8 utf8_general_ci latin1_swedish_ci 149select event_name from information_schema.events; 150event_name 151e1 152create event e2 on schedule every 10 hour do select 1; 153ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 154alter event e2 disable; 155ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 156alter event e2 rename to e3; 157ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 158drop event e2; 159ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 160drop event e1; 161ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 162unlock tables; 163lock table t1 write; 164show create event e1; 165Event sql_mode time_zone Create Event character_set_client collation_connection Database Collation 166e1 SYSTEM CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1 utf8 utf8_general_ci latin1_swedish_ci 167select event_name from information_schema.events; 168event_name 169e1 170create event e2 on schedule every 10 hour do select 1; 171ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 172alter event e2 disable; 173ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 174alter event e2 rename to e3; 175ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 176drop event e2; 177ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 178drop event e1; 179ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 180unlock tables; 181lock table t1 read, mysql.event read; 182show create event e1; 183Event sql_mode time_zone Create Event character_set_client collation_connection Database Collation 184e1 SYSTEM CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1 utf8 utf8_general_ci latin1_swedish_ci 185select event_name from information_schema.events; 186event_name 187e1 188create event e2 on schedule every 10 hour do select 1; 189ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 190alter event e2 disable; 191ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 192alter event e2 rename to e3; 193ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 194drop event e2; 195ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 196drop event e1; 197ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 198unlock tables; 199lock table t1 write, mysql.event read; 200show create event e1; 201Event sql_mode time_zone Create Event character_set_client collation_connection Database Collation 202e1 SYSTEM CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1 utf8 utf8_general_ci latin1_swedish_ci 203select event_name from information_schema.events; 204event_name 205e1 206create event e2 on schedule every 10 hour do select 1; 207ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 208alter event e2 disable; 209ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 210alter event e2 rename to e3; 211ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 212drop event e2; 213ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 214drop event e1; 215ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 216unlock tables; 217lock table t1 read, mysql.event write; 218ERROR HY000: You can't combine write-locking of system tables with other tables or lock types 219lock table t1 write, mysql.event write; 220ERROR HY000: You can't combine write-locking of system tables with other tables or lock types 221lock table mysql.event write; 222show create event e1; 223Event sql_mode time_zone Create Event character_set_client collation_connection Database Collation 224e1 SYSTEM CREATE DEFINER=`root`@`localhost` EVENT `e1` ON SCHEDULE EVERY 10 HOUR STARTS '#' ON COMPLETION NOT PRESERVE ENABLE DO select 1 utf8 utf8_general_ci latin1_swedish_ci 225select event_name from information_schema.events; 226event_name 227e1 228create event e2 on schedule every 10 hour do select 1; 229ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 230alter event e2 disable; 231ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 232alter event e2 rename to e3; 233ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 234drop event e3; 235ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 236drop event e1; 237ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 238unlock tables; 239drop event e1; 240Make sure we have left no events 241select event_name from information_schema.events; 242event_name 243 244Events in sub-statements, events and prelocking 245 246 247create event e1 on schedule every 10 hour do select 1; 248Warnings: 249Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 250create function f1() returns int 251begin 252show create event e1; 253return 1; 254end| 255ERROR 0A000: Not allowed to return a result set from a function 256create trigger trg before insert on t1 for each row 257begin 258show create event e1; 259end| 260ERROR 0A000: Not allowed to return a result set from a trigger 261create function f1() returns int 262begin 263select event_name from information_schema.events; 264return 1; 265end| 266ERROR 0A000: Not allowed to return a result set from a function 267create trigger trg before insert on t1 for each row 268begin 269select event_name from information_schema.events; 270end| 271ERROR 0A000: Not allowed to return a result set from a trigger 272create function f1() returns int 273begin 274create event e2 on schedule every 10 hour do select 1; 275return 1; 276end| 277ERROR HY000: Recursion of EVENT DDL statements is forbidden when body is present 278create function f1() returns int 279begin 280alter event e1 rename to e2; 281return 1; 282end| 283ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger 284create function f1() returns int 285begin 286drop event e2; 287return 1; 288end| 289ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger 290---------------------------------------------------------------------- 291create trigger trg before insert on t1 for each row 292begin 293set new.a= f1(); 294end| 295create function f1() returns int 296begin 297call p1(); 298return 0; 299end| 300create procedure p1() 301begin 302select event_name from information_schema.events; 303end| 304insert into t1 (a) values (1)| 305ERROR 0A000: Not allowed to return a result set from a trigger 306drop procedure p1| 307create procedure p1() 308begin 309show create event e1; 310end| 311insert into t1 (a) values (1)| 312ERROR 0A000: Not allowed to return a result set from a trigger 313drop procedure p1| 314create procedure p1() 315begin 316create temporary table tmp select event_name from information_schema.events; 317end| 318expected to work, since we redirect the output into a tmp table 319insert into t1 (a) values (1)| 320select * from tmp| 321event_name 322e1 323drop temporary table tmp| 324drop procedure p1| 325create procedure p1() 326begin 327alter event e1 rename to e2; 328end| 329insert into t1 (a) values (1)| 330ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger 331drop procedure p1| 332create procedure p1() 333begin 334drop event e1; 335end| 336insert into t1 (a) values (1)| 337ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger 338drop table t1| 339drop event e1| 340set names utf8; 341create event имя_события_в_кодировке_утф8_длиной_больше_чем_48 on schedule every 2 year do select 1; 342Warnings: 343Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 344select EVENT_NAME from information_schema.events 345where event_schema='test'; 346EVENT_NAME 347drop event имя_события_в_кодировке_утф8_длиной_больше_чем_48; 348create event 349очень_очень_очень_очень_очень_очень_очень_очень_длинная_строка_66 350on schedule every 2 year do select 1; 351ERROR 42000: Identifier name 'очень_очень_очень_очень_очень_очень_очень_очень_длин...' is too long 352create event event_35981 on schedule every 6 month on completion preserve 353disable 354do 355select 1; 356Warnings: 357Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 358The following SELECTs should all give 1 359select count(*) from information_schema.events 360where event_schema = database() and event_name = 'event_35981' and 361on_completion = 'PRESERVE'; 362count(*) 3631 364alter event event_35981 enable; 365select count(*) from information_schema.events 366where event_schema = database() and event_name = 'event_35981' and 367on_completion = 'PRESERVE'; 368count(*) 3691 370alter event event_35981 on completion not preserve; 371select count(*) from information_schema.events 372where event_schema = database() and event_name = 'event_35981' and 373on_completion = 'NOT PRESERVE'; 374count(*) 3751 376alter event event_35981 disable; 377select count(*) from information_schema.events 378where event_schema = database() and event_name = 'event_35981' and 379on_completion = 'NOT PRESERVE'; 380count(*) 3811 382alter event event_35981 on completion preserve; 383select count(*) from information_schema.events 384where event_schema = database() and event_name = 'event_35981' and 385on_completion = 'PRESERVE'; 386count(*) 3871 388drop event event_35981; 389create event event_35981 on schedule every 6 month disable 390do 391select 1; 392Warnings: 393Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 394select count(*) from information_schema.events 395where event_schema = database() and event_name = 'event_35981' and 396on_completion = 'NOT PRESERVE'; 397count(*) 3981 399drop event event_35981; 400create event event_35981 on schedule every 1 hour starts current_timestamp 401on completion not preserve 402do 403select 1; 404Warnings: 405Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 406alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00' 407 ends '1999-01-02 00:00:00'; 408ERROR HY000: Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future 409drop event event_35981; 410create event event_35981 on schedule every 1 hour starts current_timestamp 411on completion not preserve 412do 413select 1; 414Warnings: 415Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 416alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00' 417 ends '1999-01-02 00:00:00' on completion preserve; 418Warnings: 419Note 1544 Event execution time is in the past. Event has been disabled 420drop event event_35981; 421create event event_35981 on schedule every 1 hour starts current_timestamp 422on completion preserve 423do 424select 1; 425Warnings: 426Warning 1105 Event scheduler is switched off, use SET GLOBAL event_scheduler=ON to enable it. 427alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00' 428 ends '1999-01-02 00:00:00'; 429Warnings: 430Note 1544 Event execution time is in the past. Event has been disabled 431alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00' 432 ends '1999-01-02 00:00:00' on completion not preserve; 433ERROR HY000: Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future 434alter event event_35981 on schedule every 1 hour starts '1999-01-01 00:00:00' 435 ends '1999-01-02 00:00:00' on completion preserve; 436Warnings: 437Note 1544 Event execution time is in the past. Event has been disabled 438drop event event_35981; 439drop database events_test; 440