CREATE TRIGGER limit_rows_trigger
AFTER INSERT ON your_table
FOR EACH ROW
BEGIN
DECLARE row_count INT;
SELECT COUNT(*) INTO row_count FROM your_table;
IF row_count > 500 THEN
DELETE FROM your_table
ORDER BY created_at
LIMIT 1;
END IF;
END//