How to delete mysql database through shell command

MysqlDatabaseLinuxShellUbuntu

Mysql Problem Overview


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?

Mysql Solutions


Solution 1 - Mysql

Try the following command:

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

Solution 2 - Mysql

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 - Mysql

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 - Mysql

Another suitable way:

$ mysql -u you -p
<enter password>

>>> DROP DATABASE foo;

Solution 5 - Mysql

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

Solution 6 - Mysql

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

Solution 7 - Mysql

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

Solution 8 - Mysql

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

Enter password:******

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser90150View Question on Stackoverflow
Solution 1 - MysqlAlex ReisnerView Answer on Stackoverflow
Solution 2 - MysqlYadaView Answer on Stackoverflow
Solution 3 - MysqlgahooaView Answer on Stackoverflow
Solution 4 - MysqlgahooaView Answer on Stackoverflow
Solution 5 - MysqlengineerDaveView Answer on Stackoverflow
Solution 6 - MysqlIlijaView Answer on Stackoverflow
Solution 7 - MysqlBhautik NadaView Answer on Stackoverflow
Solution 8 - MysqliyadView Answer on Stackoverflow