Joe Joe - 10 months ago 40
MySQL Question

How to echo print statements while executing a sql script

We have a simple sql script which needs to be executed against a MySQL database and we would like print log statements on the progress of the script (e.g. Inserted 10 records into foo or Deleted 5 records from bar). How do we do this?

  1. I would like to know the syntax to be used for insert/update/delete statements.

  2. How do I know about the number of rows affected by my statement(s).

  3. I would also like to control printing them using a ECHO off or on command at the top of the script.

  4. The script should be portable across Windows / Linux OS.


This will give you are simple print within a sql script:

select 'This is a comment' AS '';

Alternatively, this will add some dynamic data to your status update if used directly after an update, delete, or insert command:

select concat ("Updated ", row_count(), " rows") as '';