Only import data into MysQl with matching column names

I want to synchronize data with a MySQL database. The database has 20 columns, for example.
The data comes from different sources and does not always have exactly these 20 columns.

I simply want to import the columns that match the column names in the database.

In this case, however, the node for the MySQL import returns an error in Auto-Map that something does not match here. However, I don’t want to map the columns individually each time, as this is relatively time-consuming to set in the node for many workflows.

Is there a easy solution for this?



## Information on your n8n setup
- **n8n version:** 1.27.2
- **Database (default: SQLite):**  MySQL
- **n8n EXECUTIONS_PROCESS setting (default: own, main):** own  
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**  Docker
- **Operating system:** Ubuntu

Hi @blurred, welcome to the community!

This is a tricky one and I believe it requires a bit of custom code to solve. I’ve played around a bit and came up with the below workflow. This fetches the table schema and removes all non-existent columns from the input data before inserting data into your database table.

My example database table has these four columns:

image

My mock input data has these columns instead:

image

The Code node in this workflow will remove the firstname column as it does not exist in the db table:

Afterwards, the automapping works as it should:

Here’s the full example workflow:

Hope this helps!

1 Like

Thank you for your help

2 Likes