mysqladmin Drop Database

Summary: in this tutorial, you will learn how to use mysqladmin drop database command to delete a database in a MySQL server.

mysqladmin is a client program that allows you to perform administrative database operations. You can use it to drop a database in a MySQL server

The following command drops a database from the MySQL server:

mysqladmin [options] drop db_name;Code language: plaintext (plaintext)

In this command:

  • mysqladmin invokes the mysqladmin program from the bin directory.
  • [options] specifies the database connection parameters including host, user, and password.
  • drop instructs mysqladmin to drop a database.
  • db_name is the name of the database that you want to remove.

We’ll show you how to delete the mydb database on the local database server:

First, open the Command Prompt on Windows or Terminal on Unix-like systems.

Second, drop the mydb database using the mysqladmin command:

 mysqladmin -u root -p drop mydb;Code language: plaintext (plaintext)

It’ll prompt you to enter the password for the root account.

After entering the password, the mysqladmin program will display the following confirmation:

Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'mydb' database [y/N] YCode language: plaintext (plaintext)

Third, confirm your database deletion by entering the letter Y. The mysqladmin program will delete the mydb database and show the following message:

Database "mydb" droppedCode language: plaintext (plaintext)

Behind the scenes, the mysqladmin program uses the DROP DATABASE statement to drop the database.

If you don’t want the mysqladmin to confirm before dropping the database, you can use the --force (or -f) option.

For example, the following command drops the database test without a confirmation:

mysqladmin -u root -p -f drop test;Code language: plaintext (plaintext)

This command prompts for entering the password and immediately deletes the test database. If you enter a valid password, it’ll drop the test database and return the following message:

Database "test" droppedCode language: JavaScript (javascript)

Note that if the database you want to drop does not exist, the mysqladmin program will fail and display an error.

For example, if you delete the mydbx that does not exist, you’ll get the following message:

mysqladmin: DROP DATABASE mydbx failed;
error: 'Can't drop database 'mydbx'; database doesn't exist'Code language: plaintext (plaintext)

Summary

  • Use the mysqladmin -u root -p drop db_name command to drop a database.
  • Use the --force (or -f) option in the mysqladmin command to drop a database without a confirmation.
Was this tutorial helpful?