How do I remove a MySQL database?

Mysql

Mysql Problem Overview


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?

Mysql Solutions


Solution 1 - Mysql

From the MySQL prompt:

mysql> drop database <db_name>;

Solution 2 - Mysql

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

Solution 3 - Mysql

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!

Solution 4 - Mysql

drop database <db_name>;
FLUSH PRIVILEGES;

Solution 5 - Mysql

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

Solution 6 - Mysql

For Visual Studio, in the package manager console:

 drop-database

Solution 7 - Mysql

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.

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
QuestionL&#233;o L&#233;opold Hertz 준영View Question on Stackoverflow
Solution 1 - MysqlrnicholsonView Answer on Stackoverflow
Solution 2 - MysqlsjasView Answer on Stackoverflow
Solution 3 - MysqlBenView Answer on Stackoverflow
Solution 4 - MysqlanonymousView Answer on Stackoverflow
Solution 5 - MysqlDoesEatOatsView Answer on Stackoverflow
Solution 6 - MysqlAbdullah AkçamView Answer on Stackoverflow
Solution 7 - MysqlYusma ImtiazView Answer on Stackoverflow