Home > Database > Mysql Tutorial > body text

How to Capture Rows Affected by MySQL Queries from Bash?

Susan Sarandon
Release: 2024-10-31 00:52:02
Original
243 people have browsed it

How to Capture Rows Affected by MySQL Queries from Bash?

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]"
Copy after login

or

mysql -u[user] -p[pass] `<<`QUERY_INPUT

[mysql commands]

QUERY_INPUT
Copy after login

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();
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!