MySQL command-line tool: How to find out number of rows affected by a DELETE?

mysql

Solution

You can add `SELECT ROW_COUNT();` at the end of the batch script.

Problem

I'm trying to run a script that deletes a bunch of rows in a MySQL (innodb) table in batches, by executing the following in a loop: ``` mysql --user=MyUser --password=MyPassword MyDatabase < SQL_FILE ``` where SQL_FILE contains a DELETE FROM ... LIMIT X command. I need to keep running this loop until there's no more matching rows. But unlike running in the mysql shell, the above command does not return the number of rows affected. I've tried -v and -t but neither works. How can I find out how many rows the batch script affected? Thanks!

Original source

Related problems