MySQL DROP DATABASE

DROP DATABASE deletes a database, and all the tables and data inside it.

DROP DATABASE school;
MySQL says

Query OK, 2 rows affected (0.05 sec)

The number of rows affected shows how many tables were removed.

Note: There is no undo. A dropped database is gone for ever, unless you have a backup. Always check the name twice, and take a backup first with mysqldump.

IF EXISTS

If the database does not exist, MySQL gives an error. IF EXISTS avoids it.

DROP DATABASE IF EXISTS school;

Take a backup first

mysqldump -u root -p school > school_backup.sql

To restore it later:

mysql -u root -p school < school_backup.sql

Summary

  • DROP DATABASE name; removes a database and everything in it.
  • It cannot be undone, so take a backup first.
  • Next: CREATE TABLE.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a query to get all column names of a database table
Write a query to create a new table with the data and structure of another table
Interview Questions & Answers
Write a query to create a new table which consists of data and structure copied from the other table
What is a primary key in MySQL?
What is a foreign key in MySQL?
What is the difference between CHAR and VARCHAR in MySQL?
What is normalization in MySQL?
What is AUTO_INCREMENT in MySQL?
What is the difference between primary key and unique key?