Ubuntu: How to Delete a MySQL Database via the Terminal CodeUnit 21 JAN 2011

To delete a database from a MySQL server instance, we need to make a DROP DATABASE call against the server.

First, fire up MySQL in your terminal and login as an administrator account with:

mysql -u root -p

You will be prompted for your root password before being granted access to the MySQL monitor.

Now to grab a list of available databases on the system. Running:

show databases;

Will result in quite a list of available databases being drawn on the screen (note, it only lists the databases your user account has privileges to see). Once you have located the database you wish to delete in this list we can proceed:

drop database if exists mydatabase;

This will now delete the mydatabase database from the MySQL server if it exists. If not, the drop database statement is simply ignored.

Nifty.

Related Posts:

About Craig Lotter

South African software development manager and senior application developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • Pingus

    Great!

  • sal

    how to repair database through terminal

  • Dave

    Awesome, thanks!

    • http://www.craiglotter.co.za/ Craig Lotter

      No problem!

  • emdad

    awesome, thanks :)