174

You may notice from my last question that a problem caused some more problems, Reading MySQL manuals in MySQL monitor?

My database is now unusable partly due to my interest to break things and my inability to look at error messages. I know that I should not reuse primary keys, but I would like to use them again after the removal of the database that I deteriorated. So

How can I correctly remove a MySQL database?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

7 Answers7

302

From the MySQL prompt:

mysql> drop database <db_name>;
shareef
  • 9,255
  • 13
  • 58
  • 89
rnicholson
  • 4,538
  • 1
  • 22
  • 13
35

If your database cannot be dropped, even though you have no typos in the statement and do not miss the ; at the end, enclose the database name in between backticks:

mysql> drop database `my-database`;

Backticks are for databases or columns, apostrophes are for data within these.

For more information, see this answer to Stack Overflow question When to use single quotes, double quotes, and backticks?.

Community
  • 1
  • 1
sjas
  • 18,644
  • 14
  • 87
  • 92
16

If you are using an SQL script when you are creating your database and have any users created by your script, you need to drop them too. Lastly you need to flush the users; i.e., force MySQL to read the user's privileges again.

-- DELETE ALL RECIPE

drop schema <database_name>;
-- Same as `drop database <database_name>`

drop user <a_user_name>;
-- You may need to add a hostname e.g `drop user bob@localhost`

FLUSH PRIVILEGES;

Good luck!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ben
  • 3,012
  • 1
  • 21
  • 25
  • The above SQL doesn't work in MySQL. (Maybe this of for an old version of mysql?? – Jay Apr 10 '13 at 01:30
3
drop database <db_name>;
FLUSH PRIVILEGES;
Nazik
  • 8,696
  • 27
  • 77
  • 123
anonymous
  • 39
  • 1
  • 7
    See your answer how it looks and try to format the answer correctly by editing it and don't simply post the code. Give some explanation or information or usage about your code. For example, see [this answer](http://stackoverflow.com/a/16893057/756941). – Nazik Feb 12 '14 at 05:14
0

I needed to correct the privileges.REVOKE ALL PRIVILEGES ONlogs.* FROM 'root'@'root'; GRANT ALL PRIVILEGES ONlogs.* TO 'root'@'root'WITH GRANT OPTION;

DoesEatOats
  • 625
  • 7
  • 13
0

For Visual Studio, in the package manager console:

 drop-database
Abdullah Akçam
  • 299
  • 4
  • 18
-1

If you are working in XAMPP and your query of drop database doesn't work then you can go to the operations tag where you find the column (drop the database(drop)), click that button and your database will be deleted.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yusma Imtiaz
  • 19
  • 1
  • 1
  • 2
  • You can also find the location where that database is stored on windows, using xammp. Find the location where the mysql data directory is. And then delete it. For example if your database is named logs, that might be at:E:\Program Files\xampp\mysql\data\logs – DoesEatOats Jul 20 '18 at 18:00