[mysql] How do I remove a MySQL database?

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?

This question is related to mysql

The answer is


From the MySQL prompt:

mysql> drop database <db_name>;

drop database <db_name>;
FLUSH PRIVILEGES;

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


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?.


For Visual Studio, in the package manager console:

 drop-database

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!


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.