简体   繁体   English

MySQL命令行工具:如何找出受DELETE影响的行数?

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

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(innodb)表中的一堆行:

mysql --user=MyUser --password=MyPassword MyDatabase < SQL_FILE

where SQL_FILE contains a DELETE FROM ... LIMIT X command. 其中SQL_FILE包含DELETE FROM ... LIMIT X命令。

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. 但与在mysql shell中运行不同,上面的命令不会返回受影响的行数。 I've tried -v and -t but neither works. 我试过-v和-t但是都没有用。 How can I find out how many rows the batch script affected? 如何找出批处理脚本影响的行数?

Thanks! 谢谢!

You can add SELECT ROW_COUNT(); 您可以添加SELECT ROW_COUNT(); at the end of the batch script. 在批处理脚本的末尾。

If you add option -vv it will produce more verbose output, which also contain an information about number of affected rows; 如果添加选项-vv,它将生成更详细的输出,其中还包含有关受影响行数的信息;

mysql -vv --user=MyUser --password=MyPassword MyDatabase < SQL_FILE mysql -vv --user = MyUser --password = MyPassword MyDatabase <SQL_FILE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM