Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete mysql database through shell command

People also ask

How do I delete a database in MySQL shell?

Deleting a MySQL or MariaDB databaseUse the command 'SHOW DATABASES;' in the mysql-console like in the example above. Now copy the name of the database you want to delete. To do delete a database you need the command 'DROP DATABASE'.

How do you delete a database in Linux?

If you want to delete an existing database, you can run the simple 'DROP DATABASE' command, along with the database name, as follows: DROPDATABASE database_name; Keep in mind, you can only delete or drop a database if you have the privileges to delete that database.

What is the delete command in MySQL?

DELETE FROM table_name [WHERE Clause] If the WHERE clause is not specified, then all the records will be deleted from the given MySQL table. You can specify any condition using the WHERE clause. You can delete records in a single table at a time.

Which command is used to delete a database?

The DROP DATABASE command is used to delete an existing SQL database.


Try the following command:

mysqladmin -h[hostname/localhost] -u[username] -p[password] drop [database]

In general, you can pass any query to mysql from shell with -e option.

mysql -u username -p -D dbname -e "DROP DATABASE dbname"

If you are tired of typing your password, create a (chmod 600) file ~/.my.cnf, and put in it:

[client]
user = "you"
password = "your-password"

For the sake of conversation:

echo 'DROP DATABASE foo;' | mysql

Another suitable way:

$ mysql -u you -p
<enter password>

>>> DROP DATABASE foo;

No need for mysqladmin:

just use mysql command line

mysql -u [username] -p[password] -e 'drop database db-name;'

This will send the drop command although I wouldn't pass the password this way as it'll be exposed to other users of the system via ps aux


MySQL has discontinued drop database command from mysql client shell. Need to use mysqladmin to drop a database.