How to delete mysql database through shell command

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

Each time I do this, opening the MySql query browser and logging in and deleting the database / schema.

How to remove MySQL db / schema linux shell commands in Ubuntu Linux?

+72
linux database mysql shell ubuntu
Jan 12
source share
8 answers

Try the following command:

mysqladmin -h[hostname/localhost] -u[username] -p[password] drop [database] 
+128
Jan 12 '10 at 16:44
source share

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

 mysql -u username -p -D dbname -e "DROP DATABASE dbname" 
+29
Jan 12
source share

If you are tired of entering a password, create a file (chmod 600) ~/.my.cnf and paste it:

 [client] user = "you" password = "your-password" 

To talk:

 echo 'DROP DATABASE foo;' | mysql 
+24
Jan 12
source share

Another suitable way:

 $ mysql -u you -p <enter password> >>> DROP DATABASE foo; 
+13
Jan 12
source share

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 will not pass the password this way, since it will be available to other users of the system via ps aux

+8
Jul 26 '13 at 21:17
source share

MySQL stopped the command to drop the database from the mysql client shell. You must use mysqladmin to delete the database.

+1
Aug 22 '14 at 8:45
source share

You can delete the database directly as:

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

[Enter password]

Are you sure you want to reset the hairless database [y / N]: y

+1
Sep 23 '16 at 6:59
source share
 [root@host]# mysqladmin -u root -p drop [DB] Enter password:****** 
0
Jun 13 '14 at 19:11
source share



All Articles