For each new row in Mysql trigger

Hi, I would like to use n8n to trigger a sequence whenever something occurs in my app / database.
For example, the most basic scenario is when a new users signs up for an account - this results in a new row inside the Users table.

What is the recommended way to store a variable, such as user ID somewhere in n8n?
I’m thinking this way I could:

  1. Get data from Mysql every X amount of time (trigger: interval + node: mysql)
  2. Then check which IDs are bigger than the one I have stored
  3. Do something with those IDs (let’s say send them an email)
  4. Update the state in the variable to remember for the next run, which IDs were processed.

The workflow would probably look something like the screenshot below, but I’m missing the piece that would allow me to know what IDs were processed already.

Thanks for any tips on the matter!

n8n version 0.188.0
running on Docker

Hi @Matija_Kovac, you could consider using n8n’s static workflow data to store which row you have last processed. This would require a bit of code though (check out the docs for details) and most importantly does not work when manually running/testing your workflow.

So perhaps you might want to consider adding an additional column (something such as processed_by_n8n) instead and simply update it whenever you’re processed an item (and then use it in your query, of course)?

Hi Tom,
thanks for getting back to me, both options look interesting - I’ll look into this and see what works best for my use case.

Respondendo a todos que se depararem com isto.

Eu migrei do Zapier e este era um gatilho muito utilizado que eu usava para minha aplicação. Para fazer uma sondagem estilo Zapier, criei uma tabela com 1 linha no n8n. A cada 2 minutos faço uma sondagem, trago a tabela que contém o ID da linha da tabela SQL da última execução. Depois de trazer minha tabela, a consulta SQL incluía o último ID de linha de transação. Isso é especialmente útil se o SQL com o qual você está trabalhando não faz parte de uma aplicação que você possua, então modificar o SQL é desaprovado pelo fornecedor da aplicação. Depois, bem no final da tarefa, atualizei a linha da tabela n8n com o novo ID de linha de transação executada. O único problema, que espero que o n8n tenha com uma solução integrada, é que mostra que a tarefa foi executada a cada 2 minutos, o que torna a busca por execuções difícil.