Drop the database

If you want to delete the database itself, then the DROP DATABASE command will delete the complete database along with all of the tables inside it.

Now, we will create the script mysql_14.sh to drop the database:

mysql -u user1 -pTest623@! <<MY_QUERY 

Now, save the program and run it as follows:

          $ chmod +x mysql_14.sh
          $ ./mysql_14.sh

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

ERROR 1008 (HY000) at line 2: Can't drop database 'testdb'; database doesn't exist 

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.