Removing or deleting databases
To remove or delete a database in MySQL, we use a DROP
statement. This statement is functionally the opposite of the basic CREATE
statement used previously:
DROP DATABASE <database name>;
So, for csv
, a DROP
statement would look like this:
DROP DATABASE csv;
Note that the DROP
statement not only deletes the structure of the database setup by CREATE
but also irrevocably drops all of the database data, as well.
Avoiding errors
As with the CREATE
statement, MySQL's DROP
statement also supports a test for existence. If the database you wish to drop does not exist, MySQL will throw an error. Therefore, it is good practice to use the IF EXISTS
conditional as follows:
DROP DATABASE IF EXISTS <database name>;
For a database called foo
, this statement would read:
DROP DATABASE IF EXISTS foo;
Preventing (illegal) access after a DROP
By dropping a database, one simply removes it from the list of available databases that MySQL knows about.
Note
Using DROP
does not remove...