Apurva Mayank
Apurva Mayank

Reputation: 747

How to log/write errors and warnings that occurs during a query execution

I am in process of data migration from old architecture to a new one. I have written SQL queries (insert query) for this purpose and I have used insert ignore to escape the duplication errors, and with this, they are converted into warnings. Now I want to log all these errors and warnings into a file so that stakeholders can refer to these files and check errors and warnings during the process of insertion with columns and value that was tried.

Following are the things that I checked and did:-

  1. Used tee command
  2. Used OUTFILE
  3. Checked the error.log, general log, and MySQL log but all these logs either contained server errors or just the query that was executed.
  4. I tried to execute the queries in MySQL Workbench and was able to see duplication warnings with column and value in the action output. But I think this will get lost with new query execution.

Upvotes: 0

Views: 572

Answers (1)

Gaj
Gaj

Reputation: 886

Try to do the below steps

  • Create log table with required column as per your wish
  • Create Stored procedure and move all your script to that stored procedure
  • In that stored procedure, whenever the exception raised then log those exception to your log table (i mean insert one record into that log table whenever the exception raised)
  • Take report from log table and give to stakeholders

Upvotes: 1

Related Questions