user90150
user90150

Reputation:

How to delete mysql database through shell command

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?

Upvotes: 85

Views: 180090

Answers (8)

Alex Reisner
Alex Reisner

Reputation: 29432

Try the following command:

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

Upvotes: 148

Yada
Yada

Reputation: 31225

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

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

Upvotes: 42

Bhautik Nada
Bhautik Nada

Reputation: 387

You can remove database directly as:

$ mysqladmin -h [host] -u [user] -p drop [database_name]

[Enter Password]

Do you really want to drop the 'hairfree' database [y/N]: y

Upvotes: 1

Ilija
Ilija

Reputation: 39

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

Upvotes: 3

iyad
iyad

Reputation: 21

[root@host]# mysqladmin -u root -p drop [DB]

Enter password:******

Upvotes: 0

engineerDave
engineerDave

Reputation: 3935

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

Upvotes: 11

gahooa
gahooa

Reputation: 137252

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

Upvotes: 29

gahooa
gahooa

Reputation: 137252

Another suitable way:

$ mysql -u you -p
<enter password>

>>> DROP DATABASE foo;

Upvotes: 13

Related Questions