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
No Content Found.
Interview Questions & Answers
No Content Found.