How to delete mysql database through shell command

Solution 1:

Try the following command:

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

Solution 2:

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

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

Solution 3:

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

Solution 4:

Another suitable way:

$ mysql -u you -p
<enter password>

>>> DROP DATABASE foo;

Solution 5:

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