Drop the table

If we want to remove any particular table from a database, then we need to use the DROP TABLE command. This command will remove the table definition along with all related partition information.

Now we will create the script mysql_13.sh to drop the table:

#!/bin/bash 
mysql -u user1 -pTest623@! <<MY_QUERY 
use testdb; 
DROP TABLE Authors; 
MY_QUERY 

Save the program and run it as follows:

          $ chmod +x mysql_13.sh
          $ ./mysql_13.sh
  

After executing this script, your table will have been deleted. To check whether your table has been deleted, run this same script again, and you will get the following error message:

ERROR 1051 (42S02) at line 3: Unknown table 'testdb.Authors' 

This means that your table has successfully been deleted. ...

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.