Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

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:

#!/bin/bash 
mysql -u user1 -pTest623@! <<MY_QUERY 
DROP DATABASE testdb; 
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 
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content