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