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:

mysql -u user1 -pTest623@! <<MY_QUERY 
use testdb; 
DROP TABLE Authors; 

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.