Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

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!

like image 377
ambivalence Avatar asked May 18 '10 01:05

ambivalence


1 Answers

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

like image 118
newtover Avatar answered Oct 10 '22 08:10

newtover