Ubuntu: How to Delete a MySQL Database via the Terminal

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:

  • To delete a user account from a MySQL server instance, we need to make use of a DROP USER call to the mysql.user table. 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 mo ...

  • To create a user account from a MySQL server instance, we need to make use of a CREATE USER call to the mysql.user table. 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 ...

  • To get a list of user accounts on a MySQL server instance, we need to make a SELECT call to the mysql.user table. 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. ...

  • To find out what collation and character set your database is using turns out to be pretty trivial thanks to MySQL's SHOW VARIABLES SQL statement that reveals all the inner workings of your setup. First, select your database. If you are working from the command line: USE mydatabase Then, run the SHOW VARIABLES ...

  • Backing up your MySQL database or generating a copy of it to shift around is quite a simple affair thanks to the powerful mysqldump command that ships with MySQL. To generate a backup sqldump, simply execute: mysqldump -h localhost -u [MySQL user, e.g. root] -p[database password] -c --add-drop-table --add-l ...

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.

  • Pingus

    Great!

  • sal

    how to repair database through terminal

  • Dave

    Awesome, thanks!

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

      No problem!

  • emdad

    awesome, thanks :)