Jammy Lee
Jammy Lee

Reputation: 1516

Will Mysql create new session for each event execution?

Not sure what session will be use for event execution. Will mysql always create new session or just reuse old while executing event ? what happens to user-defined variable ? what happen if different events use same user-defined variable( I know it is not good to use user-defined var here, but need to know what's the result).

some example code to explain a little bit:

CREATE EVENT myevent_a
ON SCHEDULE EVERY 1 minute
DO
  Set @a = ...
  UPDATE myschema.mytable SET mycol = @a;

CREATE EVENT myevent_b
ON SCHEDULE EVERY 1 minute
DO
  Set @a = ...
  UPDATE myschema.mytable SET mycol = @a;

will @a be read/write concurrently?

Upvotes: 2

Views: 265

Answers (1)

user3414239
user3414239

Reputation: 54

I just tested this with MySql 7.7.31.

It seem that MySql will use a new session each time the event is run.

Test for yourself by saveing the session id in a table:

INSERT INTO my_log_table (RunTime, ID)
  VALUES (NOW(), CONNECTION_ID());

So each time the event runs, it will have its own set of user-defined variables.

Upvotes: 0

Related Questions