Fix “Unknown event” Error in MySQL when Trying to Drop an Event

If you’re getting an error that reads something like “ERROR 1539 (HY000): Unknown event ‘Event1’” in MySQL when trying to drop an event, it’s probably because the event that you’re trying to drop doesn’t exist.

There are a couple of ways to address this issue. One way is to use the IF EXISTS clause so that dropping a non-existent event doesn’t cause an error. Another way is to check the name of the event that you’re trying to drop – it could be that you’re using the wrong event name.

Example of Error

Here’s an example of code that produces the error:

DROP EVENT Event1;

Output:

ERROR 1539 (HY000): Unknown event 'Event1'

In my case, the event didn’t exist and so I got an error. This is to be expected, and we’d get a similar error when trying to drop a non-existent table, view, or other object.

Solution 1

One option to prevent us getting an error is to use the IF EXISTS clause with our DROP EVENT statement:

DROP EVENT IF EXISTS Event1;

Output:

Query OK, 0 rows affected, 1 warning (0.00 sec)

Although no errors are returned when it doesn’t exist, we do get a warning. We can use SHOW WARNINGS to check the warning:

SHOW WARNINGS;

Output:

+-------+------+-----------------------------+
| Level | Code | Message                     |
+-------+------+-----------------------------+
| Note  | 1305 | Event Event1 does not exist |
+-------+------+-----------------------------+

The warning simply informs us that the event didn’t exist when we tried to drop it.

Solution 2

Another way to deal with the error is to recheck the name of the event you’re trying to drop. It could be that you’ve got a typo in your code. Or it could be that you’re reusing code that dropped another event that has already been dropped.

DROP EVENT Event2;

Output:

Query OK, 0 rows affected (0.00 sec)

In this case I changed the name of the event and it turned out to be one that existed. Therefore the event was dropped without error.