How to get number of rows deleted from mysql in schell script
Posted
by simonlord
on Stack Overflow
See other posts from Stack Overflow
or by simonlord
Published on 2010-04-13T09:11:29Z
Indexed on
2010/04/13
9:12 UTC
Read the original article
Hit count: 237
mysql
|shell-scripting
Hi all
I can't work out how to get the mysql client to return the number of rows deleted to the shell when running a delete. Does anyone know what option will enable this? Or ways around it?
Here's what i'm trying, but i get no 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 output from mysql:
deleted
999999
Which is why i have the tail -n 1 so i only pick up the count and not the column name.
Any help would be most appreciated.
© Stack Overflow or respective owner