MySQL Tutorial
MySQL Installation and Configuration
MySQL Database Operations
Database Design
MySQL Data Types
MySQL Storage Engines
MySQL Basic Operations of Tables
MySQL Constraints
MySQL Operators
MySQL Function
MySQL Manipulate Table Data
MySQL View
MySQL Indexes
MySQL Stored Procedure
MySQL Trigger
MySQL Transactions
MySQL Character Set
MySQL User Management
MySQL Database Backup and Recovery
MySQL Log
MySQL Performance Optimization
The DROP DATABASE
statement in MySQL is used to delete an existing database in MySQL, including all of its tables and data.
Important: Be careful with the DROP DATABASE statement. Once the database is deleted, you cannot retrieve it.
Prerequisites:
Tutorial:
To start the mysql
command-line client, open your terminal or command prompt, and enter:
mysql -u [username] -p
Replace [username]
with your MySQL username and enter your password when prompted.
The basic syntax for using the DROP DATABASE
statement is as follows:
DROP DATABASE database_name;
Replace database_name
with the name of the database you want to delete.
For example, to delete a database named mydb
, you would use:
DROP DATABASE mydb;
This will delete the database named mydb
along with all of its tables and data.
EXIT;
By using the DROP DATABASE
statement in MySQL, you can easily delete databases. This can be useful when you want to clean up unused databases, but always be sure you want to permanently delete the database before using this command.
Dropping a MySQL Database with DROP DATABASE:
DROP DATABASE database_name;
DROP DATABASE mydatabase;
Dropping Multiple Databases in a Single MySQL Statement:
DROP DATABASE db1, db2, db3;
Preventing Accidental Deletion with MySQL DROP DATABASE:
DROP DATABASE IF EXISTS mydatabase;
Dropping Databases with Specific Character Sets in MySQL:
DROP DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci;