MySql 5.6 event is not running, but other events are running - mysql

I have a MySql 5.6.10 database with the event scheduler enabled.
There are several events that are currently running successfully. I disabled one event and then after enabling it again, i noticed that it wasn't running. I tried disabling and enabling a few times, but still the event was not starting. So, i dropped the event and recreated it. That still didn't work, and the event will not run.
The event calls a stored procedure and I can manually run the CALL proc() that is in the event, and that works.
I created a test table and a test event to insert into that table, and that one doesn't work either.
Here is the test event i created:
CREATE EVENT test_event_01
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE
ON COMPLETION PRESERVE
DO
BEGIN
INSERT INTO test_db.test_event_msg(message_text,createdDate)
VALUES('Test MySQL Event 1',UTC_TIMESTAMP());
END
Any thoughts or suggestions that I can try or check?
Thank for any help!

As I wrote in the last comment, rebooting the MySQL instance resolved the issue with the event scheduler.

Related

Why my MYSQL event scheduler stops every night at midnight?

So i have this database running on a Synology NAS, for a restaurant's app made with Laravel, and i have this event here that should start every day at 4am
The content of this event is nothing special:
UPDATE shipping_times SET shipping_times.available = shipping_times.max_quantity
Thing is, every night at midnight the event scheduler variable auto sets to OFF even if i do GLOBAL event_scheduler = ON.
This is quite a problem since the event is used to "replenish" available orders.
Since my event should occur at 4AM i don't think the problem is event-related.
What could it be?
Alternative: Laravel Task Scheduling
Laravel Tasks come to mind for solving this instead: https://laravel.com/docs/8.x/scheduling
(other Laravel version docs available there as well)
Adding recurring tasks in this way puts them all in one place instead of hidden somewhere in a menu. They are also independant of your elusive event_scheduler.
You can also use a command and call it from the task scheduling code. See BKF's comment.
Are your events firing?
I am not sure but could it be true the event is only firing if you always have traffic between 00:00 and 04:00? Laravel Tasks also fire after the fact, AFAIK.
Add this to my.cnf (or whaterver the config file is):
event_scheduler = ON
and restart mysqld.
Apparently, something is shutting down MySQL every night, perhaps a backup? The above setting will turn it on each time it restarts.

MySQL scheduled event doesn't work on replica instance once it becomes master during failover

Given MySQL InnoDB 8 cluster with router, master and two replicas.
There is trigger for table_1 to copy data to table_2 every time data inserted to table_1.
There is scheduled event that creates daily partitions on table_3.
By design trigger and scheduled event enabled only for source (current master) instance and disabled in replicas.
Once master goes down, and one of replicas become master the trigger and scheduled event doesn't work without manually enabling them. What are workarounds and practices to cause it work automatically?
Following documentation:
https://dev.mysql.com/doc/refman/8.0/en/replication-features-invoked.html
When promoting a replica having such events to a source, you must
enable each event using ALTER EVENT event_name ENABLE, where
event_name is the name of the event.
Seems like MySQL server doesn't support this functionality automatically. External job scheduler should be used to trigger stored procedures.

Why is MySQL Event Scheduler Stuck Opening Tables?

I'm using MySQL 8.0.21 From the MySQL Community Installer on Windows 10 updated to version2004 and for some reason if I create a event in the event scheduler, which calls a procedure once every second (regardless of what that SP actually does, I'll explain my test case) - my CPU maxes out and when I look at the active connections in MySQL Workbench, it stacks up a ton of worker threads which stall on the "Opening Tables" state. My PC freezes, I have to edit the event to be disabled, stop the MySQL process in Task Manager and Start the service again.
TEST CASE
During setup of a brand new server, I used all default settings, except I enabled the general log and I use the new 8.0+ mysql_sha2_password encryption (although I ALTER USER to mysql_native_password for phpmyadmin so that might revert it, I'm honestly not sure)
I create a new Schema called "Test"
I create one Table called
"TestTable" has only one column called "column1" INT
I then create a Stored Procedure "TestProc" which does "SELECT COUNT(*) FROM
TestTable;" Adjusts Priv.'s, DEFINER::Definer is root#localhost and
Reads SQL
And Finally I create an Event called "TestEvent" which does
"CALL TestProc()s" Reoccurring every 1/sec, preserve on Complete, and
definer is root#localhost
restart server before event is fired.
Also, if I enable the event, or create it, it'll run without issue, it's important to note that the issue begins when the event scheduler is left on, and the event is left enabled, then the server is restarted from the services in task manager. Immediately the CPU jacks up to max and active connections show threads stacking up without completing.
Any clues are appreciated, I find no actual errors nor do I have any idea where to begin debugging anymore. I've tried skipping grant tables (but obviously that's not optimal, and didn't work).
I did find a hint when reviewing the MySQL 8.0+ docs
"If a repeating event does not terminate within its scheduling interval, the result may be multiple instances of the event executing simultaneously. If this is undesirable, you should institute a mechanism to prevent simultaneous instances. For example, you could use the GET_LOCK() function, or row or table locking. " from
However, when analyzing there does not appear to be any locks, nor should I need to implement such manually just for this test case (or my actual program)
UPDATE
Up to this point, albeit a rather niche bug, I do believe that is exactly what this is, and I have posted it on MySQL bug forum. Reference post is here:
The answer actually has turned out to be a bug which is reproducible - Bug#: 100449

Create Trigger in PHPMyAdmin to Repair Table on Crash

I'm running PHPBB (most up-to-date non-beta version) and in the last 3 months, the error appears during a search every few days:
'phpbb_search_wordmatch' is marked as crashed and last (automatic?) repair failed
To fix it, I then just run a repair on the table. I am still working on a way to figure out why this keeps crashing. The host was not helpful and it could be that the table is too large for the server (700 mb or so)
My Question: Could I create a trigger in PHPMyAdmin in the meantime to automatically repair the table whenever this error happens? You see it on the table in PMA when you go to access it, so there must be some entry that I can use to create the trigger.
Unfortunately this issue is difficult to fix for me being on a shared server, and all resources online say to contact the host, so as long as I can at least get it to fix itself when it happens.
You may be better off setting up a scheduled task. I'm not aware of how you could create a trigger that detects when the table needs repair; I don't believe there are hooks for the logic to detect that situation and cause a procedure to run.
From the database, there's an Events tab where you can enable the MySQL event scheduler and create an event which would run, say, once per week and run the SQL statement to repair the table. It's still not ideal, but I think it's better than using a trigger in this case.

MySQL Event Scheduling

I have a MySQL event scheduled to run everyday at midnight - But the database server is shutdown everyday evening and is restarted every morning, but not necessarily at the same time. For instance the server is started at: 10AM, I still need the event to be executed for the day, though it was scheduled for 12AM. I tested this scenario in ORACLE and it works, but doesn't quite in MySQL. Do you have a suggestion?
Thanks in advance,
Abhilash
Direct support for this behaviour was submitted as a feature request in bug #46813. It is still "awaiting triage":
The event scheduler should be able to periodically check for, and catch up on, missed events. While events that need to run this way can be scheduled using Task Scheduler on Windows and anacron on Mac and *nix, this is inelegant and platform-dependent.
As the bug report suggests, you can schedule such events using software that is external to MySQL. Alternatively, one could use MySQL's init-file option to specify a file containing commands that should be executed on startup; using that one could check the INFORMATION_SCHEMA.EVENTS table: compare LAST_EXECUTED column against event schedule and execute EVENT_DEFINITION if a scheduled event was missed.
Sorry, but MySQL doesn't handle this. If the event is missed, it's missed. It doesn't try to run it again later.
What you could do is make a table that logs when an event was last run (the date), then schedule it for each hour, but before running check if it already ran that day. That way the first time it runs after midnight it will activate.
You can create an event that would fire every hour. Create additional table to store information about event's firing.
Do these steps in the event:
check if event was fired - read info. from the table
do the code if the event stil was not fired, write information (the date) into the table.