Capturing Rows Affected by MySQL Queries from bash
When executing MySQL queries or commands from bash using the commands:
mysql -u[user] -p[pass] -e "[mysql commands]"
or
mysql -u[user] -p[pass] `<<`QUERY_INPUT [mysql commands] QUERY_INPUT
you may encounter the need to determine the number of rows affected by the executed query.
To retrieve this information, you can't simply capture the output of the query as a variable, as doing so won't return the row count. Instead, consider adding the following statement to the end of your batch of MySQL commands:
SELECT ROW_COUNT();
This statement will return the number of rows affected by the preceding queries. By parsing the output of the modified batch, you can then retrieve the desired row count.
The above is the detailed content of How to Capture Rows Affected by MySQL Queries from Bash?. For more information, please follow other related articles on the PHP Chinese website!