How to delete mysql database through shell command How to delete mysql database through shell command linux linux

How to delete mysql database through shell command


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