How to delete mysql database through shell command

Viewed 171909

I use the pylons and sqlalchemy. I constantly update the schema files and delete and recreate the database so that new schema can be made.

Every time I do this by opening the MySql Query Browser and login and delete the database/schema.

How do I delete the MySQL db/schema thorough linux shell commands in Ubuntu Linux?

8 Answers

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;
Related