How to get the number of lines deleted from mysql in a shell script

I cannot work out how to get the mysql client to return the number of rows deleted to the shell when delete is run. Does anyone know what option this would allow? Or around him?

This is what I am trying, but I am not getting the output:

#!/bin/bash
deleted=`mysql mydb -e "delete from mytable where insertedtime < '2010-04-01 00:00:00'"|tail -n 1`

      

I was expecting something like this as the result from mysql:

deleted
999999

      

This is why I have a -n 1 tail, so I am only picking up the count, not the column name.

When running the command manually (mysql mydb -e "remove from mytable where time is inserted <'2010-04-01 00:00:00'"), there is no exit. When running the command interactively when starting the mysql client i ge do the following:

mysql>delete from mytable where insertedtime < '2010-04-01 00:00:00';
Query OK, 0 rows affected (0.00 sec)

      

I want the strings associated with count to end up in my shell variable.

Any help would be most appreciated.

+2


a source to share


3 answers


This question was asked earlier: How to get the number of affected rows when executing a MySQL query from bash?



+3


a source


 deleted=`mysql mydb -e "delete from mytable where insertedtime < '2010-04-01 00:00:00'"|tail -n 1`


 int icount = mysql_CountRow(deleted);

      



it works for me, try this.

0


a source


add "-vv"

mysql mydb -e "remove from mytable where inserttime <'2010-04-01 00:00:00' -vv

https://dba.stackexchange.com/questions/23527/how-can-you-output-update-insert-query-results-when-using-mysql-e-execute

0


a source







All Articles