简体   繁体   中英

How to run a query asynchronously from MySQL Workbench

Say you have a query you want to run on your database, but you know that query is going to take a long time to complete, and you don't have direct access to the machine where MySQL is running, or to some other endpoint which has a stable connection with that machine. What do you do?

Well, you create a one time event that performs the necessary query.

Something like this:

CREATE EVENT <event_name>
ON SCHEDULE 
AT CURRENT_TIMESTAMP + INTERVAL 10 SECOND
ENABLE DO 
BEGIN
    -- log the event started
    INSERT INTO EventLogs (`Name`, `Start`, `Query`)
    VALUES (<event_name>, CURRENT_TIMESTAMP, <query_string>);
    -- run the query
    ....
    ...    <query>
    ....
    -- log the event done
    UPDATE EventLogs 
    SET `Done` = CURRENT_TIMESTAMP 
    WHERE `Name` = <event_name>;
END

The above template can handle any arbitrary query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM