Deleting data

If the need arises to delete a row, or multiple rows of a table because the data has become obsolete, then we have to use the DELETE command. When we want to make large-scale deletions in a table, this command is very handy.

Now, create the script mysql_10.sh to delete the record:

#!/bin/bash 
mysql -u user1 -pTest623@! <<MY_QUERY 
use testdb; 
DELETE FROM Authors WHERE Name = 'Mansi Joshi'; 
select * from Authors; 
MY_QUERY 

Now, save the program and run it as follows:

          $ chmod +x mysql_10.sh
          $ ./mysql_10.sh
  

The output will be:

    Id    Name
    2     Charles Dickens
    3     Jane Austen
    4     George Orwell
    5     Oscan Wilde
  

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.